我有這樣的表稱爲Table1
如下:COUNT帶日期區間
UserID Date
1 01/01/09
1 14/01/09
1 25/01/09
1 01/02/09
1 15/02/09
2 02/02/09
2 15/02/09
我試圖返回計數的MIN(Date)
30天之間倍MIN(Date)
這是DATEADD(day,30,MIN(DATE))
後的數字結果。因此,這將是這個樣子:
UserID Count
1 3
2 2
下面這段代碼是錯誤的,但它表達了什麼,我想實現:
SELECT COUNT(1) AS Count
FROM Table1
GROUP BY UserID
WHERE Date BETWEEN MIN(Date) AND DATEADD(day,30,MIN(DATE))
歡呼隊友!!!! – super9 2009-09-17 11:59:27