常用sql記錄

1.mysql內實現rownum

SELECT 
  @rownum := @rownum +1 AS rownum,
  e.*
FROM
  (SELECT 
    @rownum := 0) r,
  employee e

2.獲取出重複的記錄,保留最新一條

SELECT a.createTime,a.userId FROM short_video_entity a
LEFT JOIN short_video_entity b ON a.userId = b.userId
AND a.createTime < b.createTime
GROUP BY a.createTime, a.userId
HAVING count(b.id) < 1 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章