最近有一個需求是要我在用戶所有發過的短視頻中找到每一個用戶最新發送的一條短視頻網上找了一下感覺挺好用的所以就記錄下來
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
這條sql 確實可以達到要求 但是我不清楚它為什么要這樣寫 a.createTime < b.createTime 在我 看來取最新時間應該是 a.createTime >b.createTime 希望看到這條隨筆的大神們留下言解答下這個問題
去掉表中重復記錄並且只保留id最小的一條記錄(這個是多個字段重復)
DELETE n1 FROM msg_remind_my n1, msg_remind_my n2 WHERE n1.id > n2.id
AND n1.type = n2.type AND n1.contentId = n2.contentId AND n1.remindType = n2.remindType AND n1.remindUserId = n2.remindUserId
