select count(列名) from 表名 #查询列中不同字段数
distinct 去重
where 条件查询 在group by 之前
hving 在 group by 之后
如果在from 后面的表必须得起别名
在 where 后面的表不需要
SQL 语句的书写顺序如下:
SELECT -> FROM -> WHERE -> GROUP BY -> HAVING -> ORDER BY
SQL 语句的执行顺序如下:
FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY
select语句的处理顺序
- FROM
- ON
- JOIN
- WHERE
- GROUP BY
- WITH CUBE 或 WITH ROLLUP
- HAVING
- SELECT
- DISTINCT
- ORDER BY
- TOP
- mod(id, 2) = 1 #条件判断取模运算<br>order by rating Desc #按rating值排列 desc 反向<br><br><br><br><br>
复制代码- update Salary SET sex = if(sex = 'm','f','m') #1. update 表名 set 条件判断语句 # 2. if判断 if(列对象 = 值,case1,case2) 若为真,则执行case1,否则执行case2
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |