还有其他方法可以编写此查询吗?我尝试在子查询中执行此操作,但由于有多个列,它不起作用。看起来这个查询只能自己工作。请纠正我
记录
PK记录Id
日期查看
看车
我试过这个
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
在我尝试过的许多其他查询中,我不知道如何让它工作。
简而言之,对于特定日期,我想获取查看次数最多的汽车。
喜欢:日期查看最喜欢的CarOfTheDay
2012-09-22 | Nissan
2012-09-23 | BMW