表里有兩列資料分別是ID和DATE,怎么查詢DATE不在30天內的ID呢
表 希望輸出
id date id
1 5/1 4
2 5/2
3 5/3
1 4/1
2 4/2
3 4/3
4 4/4
1 3/1
2 3/2
3 3/3
4 3/4
現在查詢date在30天內的可以實作,輸出1/2/3
查詢date在30天外的也可以實作,輸出1/2/3/4
就是無法輸出30天內無記錄的,輸出4
uj5u.com熱心網友回復:
select distinct id from tb awhere not exists (select 1 from tb b where a.id=b.id and b.date>date_add(now(),interval -30 day))
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/16677.html
標籤:MySQL
上一篇:saas 多資料庫批量更新
下一篇:如何獲取虛擬數字火幣的實時行情?
