执行顺序如下所示,原因太长就不写了

(8) SELECT <select_list>
(9) DISTINCT <select_list>
(1) FROM <left_table>
(3) <join_type> JOIN <right_table>
(2) ON <join_condition>
(4) WHERE <where_condition>
(5) GROUP BY <group_by_list>
(6) WITH {CUBE|ROLLUP}
(7) HAVING <having_condition>
(10) ORDER BY <order_by_list>
(11) LIMIT <limit_number>

这里看到一个SQL题目:查询学生总成绩的前三名,给出MySQL和Oracle的写法

namecoursegrade
nickyuwen88
jackshuxue95
nickshuxue68
jackyuwen96
susanyuwen100
susanshuxue95
leeyuwen100
leeshuxue95
zhangyuwen58
zhangshuxue91

MySQL使用LIMIT关键字:

SELECT name
FROM student_grade
GROUP BY name
ORDER BY sum(grade) DESC
LIMIT 0,3

Oracle使用ROWNUM关键字

select name FROM(
    SELECT name
    FROM student_grade
    GROUP BY name
    ORDER BY sum(grade) DESC
)WHERE rownum <=3;

完整的SELECT语句结构:

SELECT
FROM
WHERE
HAVING
ORDER BY
WITH

table_name

1、查询数值型数据:

SELECT id,name,age FROM table_name WHERE age > 20;

查询谓词:
,=,<,<>,!=,!>,!<,=>,=<

   <>  !=  效果是一样的

2、查询字符串

SELECT id,name,age FROM table_name  WHERE name like ‘%张%’

%代表任意字符

3、查询非空数据

<s>SELECT * FROM table_name WHERE address <> "" order by addtime desc</s>

    SELECT COUNT(id) FROM table_name WHERE id IS NOT NULL






- 阅读剩余部分 -