user price time
Chan 300 2015-02-10
Chan 200 2015-02-10
Chan 100 2015-02-11
Chan 200 2015-02-12
Chan 200 2015-02-12
Chan 200 2015-02-12
Chan 400 2015-02-13
Phoebe 300 2015-02-10
....
我想选择像2015-02-10到2015-02-16这样的时期,如果用户每天支付相等或超过500,将计为一,例如chan
,他花了500在02-12,02-10,600,因此计数结果是2,怎么办?
答案 0 :(得分:0)
我使用CASE
语句来确定大于或等于500的价格并将其计为一。然后我SUM
得到总数。请尝试我的查询:
SELECT
time,
user,
COUNT(price)CountResult
FROM YourTable
WHERE price>=500 AND time BETWEEN 2015-02-10 AND 2015-02-16
GROUP BY user,time