过滤和排序数据

Posted 丿随缘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了过滤和排序数据相关的知识,希望对你有一定的参考价值。

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 ;

 

以上是关于过滤和排序数据的主要内容,如果未能解决你的问题,请参考以下文章

Primefaces数据表排序和过滤直到rowSelect才起作用

如何使用React过滤和排序相同的表数据?

SQL语句检索数据排序及过滤

angularjs中的排序和过滤

通过排序和过滤删除重复项

排序和过滤