Copyright (C) 2000-2012 |
GNU Info (mysql.info)Calculating daysCalculating visits per day -------------------------- The following shows an idea of how you can use the bit group functions to calculate the number of days per month a user has visited a web page. CREATE TABLE t1 (year YEAR(4), month INT(2) UNSIGNED ZEROFILL, day INT(2) UNSIGNED ZEROFILL); INSERT INTO t1 VALUES(2000,1,1),(2000,1,20),(2000,1,30),(2000,2,2),(2000,2,23),(2000,2,23); SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1 GROUP BY year,month; Which returns: +------+-------+------+ | year | month | days | +------+-------+------+ | 2000 | 01 | 3 | | 2000 | 02 | 2 | +------+-------+------+ The above calculates how many different days was used for a given year/month combination, with automatic removal of duplicate entries. automatically generated by info2www version 1.2.2.9 |