是否有任何其他方式來編寫此查詢? 我試圖在子查詢中做它,但它不工作,因爲有多個列。看起來這個查詢只能自行工作。請指正最常見的值子查詢MySql
記錄
PK的recordId
dateViewed
CarViewed
我想這
SELECT R.`dateViewed` FROM Records ,(
SELECT R.CarViewed, COUNT(R.CarViewed) as cnt FROM Records R
GROUP BY R.CarViewed
ORDER BY cnt DESC
LIMIT 1) AS favouriteCarOfTheDay
GROUP BY R.`dateViewed
然後我嘗試這個
SELECT R.`dateViewed` ,COUNT(R.CarViewed) as cnt FROM Records ,
(
SELECT R.CarViewed FROM Records R
GROUP BY R.CarViewed
ORDER BY cnt DESC
LIMIT 1) AS favouriteCarOfTheDay
GROUP BY R.`dateViewed
沿着我嘗試過的許多其他查詢,我不知道如何讓它工作。
簡而言之,我希望獲得最常見的汽車。
像: dateViewed favouriteCarOfTheDay
2012-09-22 | Nissan
2012-09-23 | BMW
至於我可以看到,將在總回報的一個記錄。我認爲他希望每天都有記錄。 –
它按照查看日期分組,所以沒有一個記錄 –
但是,最終的LIMIT 1是不是意味着它只返回一條記錄? –