首页 > 编程语言 > 详细

过滤和排序数据

时间:2017-07-26 19:07:29      阅读:222      评论:0      收藏:0      [点我收藏+]

1.过滤:

SELECT    *|{[DISTINCT] column|expression [alias],...}
FROM    table
[WHERE    condition(s)];

2.字符:

SELECT last_name, job_id, department_id
FROM   employees
WHERE  last_name = Whalen;

3.比较运算符:

BETWEEN ...AND...(在两个值之间 (包含边界))

SELECT last_name, salary
FROM   employees
WHERE  salary BETWEEN 2500 AND 3500;

IN(set) (等于值列表中的一个)

SELECT employee_id, last_name, salary, manager_id
FROM   employees
WHERE  manager_id IN (100, 101, 201);

LIKE(模糊查询)

SELECT    first_name
FROM     employees
WHERE    first_name LIKE S%;

IS NULL(空值)

SELECT last_name, manager_id
FROM   employees
WHERE  manager_id IS NULL;

4.逻辑运算:

AND(逻辑并)

SELECT employee_id, last_name, job_id, salary
FROM   employees
WHERE  salary >=10000
AND    job_id LIKE %MAN%;

OR(逻辑或)

SELECT employee_id, last_name, job_id, salary
FROM   employees
WHERE  salary >= 10000
OR     job_id LIKE %MAN%;

NOT(逻辑否)

SELECT last_name, job_id
FROM   emp
WHERE  job_id 
       NOT IN (IT_PROG, ST_CLERK, SA_REP);

5.ORDER BY子句

使用 ORDER BY 子句排序 。

ASC: 升序

SELECT   last_name, job_id, department_id, hire_date
FROM     employees
ORDER BY hire_date ASC ;

 

 

DESC: 降序

SELECT   last_name, job_id, department_id, hire_date
FROM     employees
ORDER BY hire_date DESC ;

 

SELECT   last_name, job_id, department_id, hire_date
FROM     employees
ORDER BY hire_date ;

 

过滤和排序数据

原文:http://www.cnblogs.com/adada/p/7241337.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!