mysql位函数的使用
查询每个月的访问天数
mysql> create table t1 (year YEAR(4),month int(2) unsigned zerofill,day int(2) u nsigned zerofill);
mysql> select * from t1; +------+-------+------+ | year | month | day | +------+-------+------+ | 2000 | 01 | 01 | | 2000 | 01 | 20 | | 2000 | 01 | 30 | | 2000 | 02 | 02 | | 2000 | 02 | 23 | | 2000 | 02 | 23 | +------+-------+------+
因为同一天会访问多次,所以仅仅使用group by year,month不准确,可以采用bit_count和bit_or来统计
SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1 group by year,month