如何在上周获得最大重复值

时间:2012-07-11 08:06:49

标签: mysql

我有一个包含3个字段的表property_viewers; id,property_id,date。我需要在上周找到最大的property_id重复。我该怎么办......

3 个答案:

答案 0 :(得分:1)

试试这个:

select *, count(1)  from property_viewers where DATEDIFF(date, DATE(now()))<8 group by property_id order by count(1) desc

答案 1 :(得分:0)

select property_id, count(property_id)  from property_viewers 
where `date` between 'weekSTartDate' and 'weekEndDate' 
group by property_id order by count(property_id) desc;

答案 2 :(得分:0)

SELECT property_id
FROM property_viewers
WHERE date BETWEEN 
    CURRENT_DATE() - INTERVAL (7+WEEKDAY(CURRENT_DATE())) DAY AND   //Monday last week
    CURRENT_DATE() - INTERVAL (1+WEEKDAY(CURRENT_DATE())) DAY       //Sunday last week
GROUP BY property_id
ORDER BY COUNT(property_id) DESC