2012-07-11 52 views
1

我有一個表property_viewers有3個字段; id,property_id,日期。我需要在上週找到最大限度的property_id。我應如何進行?如何在上週獲得最大重複值

+0

最大PROPERTY_ID,或最大重複? – 2012-07-11 08:15:55

+0

@PugganSe最近重複 – 2012-07-11 08:16:36

+0

上週,作爲最後7天或星期一到星期日? – 2012-07-11 08:17:23

回答

1

試試這個:

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

需要檢查上週的約束也... – 2012-07-11 08:15:32

+0

@KodePlus:謝謝你的建議,現在檢查.. – 2012-07-11 08:19:25

+0

那不是星期一到星期日 – 2012-07-11 08:23:07

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; 
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