我需要編寫一個查詢,我需要從表中檢索數據。mysql相關查詢
Table
===================================
ID | userID | Status | date |
===================================
1 3333 Queued xxxx
2 4444 Queued yyyy
3 5555 Finished zzzzz
5 6666 Queued iiiii
6 7777 Queued kkkkk
現在我只想檢索如果狀態=「排隊」,並與狀態=「排隊」行均超過2行,並用最新的ID行。即我想要的答案是ID = 6
我試着用下面的查詢
select * from t1 where status = "Queued" GROUP BY status HAVING count(status) > 2 ORDER BY ID DESC limit 1