如何编写一个循环来在mysql中进行计算

时间:2012-08-07 13:33:36

标签: mysql

这是我的基本mysql查询,它用于计算每日用户数,所以我需要在2012-01-30至2012-02-19执行此操作,而不是手动修改它,有什么好方法吗?

select count(distinct user) FROM video WHERE date >= '2012-01-30 00:00' AND date <= '2012-01-30 23:55';


select count(distinct user) FROM video WHERE date >= '2012-01-31 00:00' AND date <= '2012-01-31 23:55';

...

1 个答案:

答案 0 :(得分:2)

SELECT DATE(date) AS date, COUNT(DISTINCT user) FROM video
WHERE date >= '2012-01-30 00:00' AND date_pl <= '2012-02-19 00:00'
GROUP BY DATE(date)