1.占位符
半角符“_”代表占位符,表示需要多少個(gè)位置
image.png
2.分組獲取最優(yōu)
這里有一張這樣的數(shù)據(jù)表士鸥,需求是根據(jù)error_type分組然后取status最小的第一條數(shù)據(jù)闲孤,如圖:
select t.* from (
select e.* from error_record e where e.status > 0 and e.error_type > 0 order by e.status limit 1000
) t group by t.error_type
查詢結(jié)果
這種寫法可以實(shí)現(xiàn)我們的需求, 在臨時(shí)表內(nèi)部排序時(shí)用limit字段固定排序, 然后在臨時(shí)表外分組就可以改變group by默認(rèn)排序的問題(注: 原表中error_typ為3的數(shù)據(jù)只有一條就是status: 2)烤礁。