sql语句查询每天下注人数有多少,userId是用户的唯一编号,下注一次就是一条记录
要求使用group by函数。to_days 函数
select userId, TO_DAYS(年月日如160812) from 表名 group by userId
SQL TO_DAYS()-给定一个日期date,返回一个天数(自0年的天数)。
select count(1) from table group by date(日期);
参考自:MySQL如何优化GROUP BY http://www.data.5helpyou.com/article237.html
select count(distinct(userId)),date from table where group by date
select count(distinct(userId)),date from table group by date
日期格式化一下就可以。
select count (userId) as peoples from 表名 where to_days(in_date) - (to_day(now())) = 0 group by userId
查到的数据为当天下注的人数 ,保存在peoples字段下。
对了, 上面代码中的in_date为插入数据的日期
select to_days(日期),count(userid) as ''下注人数 from 表 where 条件 group by to_days(日期)
select to_days(日期),count(userid) as '下注人数' from 表 where 条件 group by to_days(日期)