MySQL Visitor Calculation
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);
The table contains the following -
a) year-month-day values
In order to search, how many days these visitors search take place -
SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1
GROUP BY year,month;
Which returns:
+------+-------+------+
| year | month | days |
+------+-------+------+
| 2007 | 01 | 3 |
| 2007 | 02 | 2 |
+------+-------+------+
|