此查询:
SELECT date_format(At,'%d %M %Y') as At,
COUNT(ID) as ids
FROM `purchases`
WHERE At >= '2013-12-08 00:00:00' AND At <= '2013-12-09 23:59:59'
GROUP BY date_format(At,'%D%M%Y')
不好!答案应该是数字(一段时间)/这个数字ids。代表唯一一个在我的商店里工作一天甚至是一天5次的身份证。
column1:At
colunm2:ID
- '2013-09-23 11:00:14', 2:34299989
- '2013-09-23 11:00:51', 1:100004003444031
- '2013-09-23 11:01:02', 1:100001273059371
- '2013-09-23 11:01:02', 1:100001476045767
- '2013-09-23 11:01:11', 1:1081392435
- '2013-09-23 11:01:17', 1:100001436850024
- '2013-09-23 11:01:30', 1:100000663028305
- '2013-09-23 11:01:38', 1:100003991975009
对于这个表格表示抱歉,我无法做得更好。
答案 0 :(得分:0)
在该范围内每天至少进行一次购买的ID
个数:
SELECT COUNT(ID) FROM (
SELECT ID
FROM purchases
WHERE At >= '2013-12-08' AND At < '2013-12-10'
GROUP BY ID
HAVING COUNT(DISTINCT DATE(At)) = DATEDIFF('2013-12-10','2013-12-08')
) t
在该范围内至少一天至少购买5次的ID
个数:
SELECT COUNT(DISTINCT ID) FROM (
SELECT ID, DATE(At)
FROM purchases
WHERE At >= '2013-12-08' AND At < '2013-12-10'
GROUP BY ID, DATE(At)
HAVING COUNT(*) >= 5
) t
(如果您在DISTINCT
在该范围内的一天内至少进行了5次购买的次数之后,即从最后一次查询中移除ID
,即计算相同{{1}多次,如果它在多天内每次至少购买5次)。