- limit的不同用法和區(qū)別
limit 3 #取前3條數(shù)據(jù),等同于limit 0,3 (1)
limit 1,3 #跳過(guò)第1條數(shù)據(jù),取其后3條數(shù)據(jù) (2)
limit 3 offset 1 #跳過(guò)第1條數(shù)據(jù),取其后3條數(shù)據(jù),和(2)的效果一致 (3)
-
SQL語(yǔ)句的執(zhí)行順序
from > where > group by > 聚合函數(shù) > having > select > distinct > order by > limit
where的一種錯(cuò)誤用法
錯(cuò)誤示例:
where v1.date = v2.date = '2020-01-01'
正確示例:
where v1.date = v2.date and v1.date = '2020-01-01'
或
where v1.date = '2020-01-01' and v2.date = '2020-01-01'
-
distinct 的使用注意點(diǎn)
distinct 應(yīng)用到多個(gè)字段時(shí),其應(yīng)用范圍是其后的所有字段,只有每個(gè)字段中的元素 同時(shí)相同時(shí)才進(jìn)行去重操作
可以進(jìn)行如下語(yǔ)句操作:
select distinct * from xxx
-
關(guān)于取余操作
N % M 或 mod(N,M) ——N/M取余