1 去重查詢mysql
select distinct id from user_info where xxxxxxsql
2 group by 分組查詢中排序unix
group by自己沒有排序功能,這多是mysql不完美的地方,可是咱們能夠這樣作排序
select attack_id, time from (select * from attack_log where (time+172800) < unix_timestamp(now()) order by time desc) attack_log group by attack_idselect
*注:先經過排序行成一個集合,而後再去改集合中去查,這樣分組就實現了排序查詢im
3 查找符合要求的 前兩個數據數據
select attack_id,time from attack_log a where (select count(*) from attack_log where attack_id = a.attack_id and time > a.time) <2查詢
*注:where 後面 實際上是一個bool值。經過bool值來過濾 符合要求的數據集合