How to count rows of week

hello.

i need count rows of week and tried this query with correct output:

mysql> SELECT
	zn,
	COUNT(*) AS q,
	CURRENT_DATE () AS today,
	DATE_SUB(
		CURRENT_DATE (),
		INTERVAL 1 WEEK
	) AS WEEK
FROM
	tbl_cc80
WHERE
	1
AND Day_of_the_event_s BETWEEN DATE_SUB(
	CURRENT_DATE (),
	INTERVAL 1 WEEK
)
AND CURRENT_DATE ()
GROUP BY
	Zn,
	DATE_SUB(
		CURRENT_DATE (),
		INTERVAL 1 WEEK
	)
ORDER BY
	Day_of_the_event_s DESC;
+------------------+----+------------+------------+
| zn               | q  | today      | WEEK       |
+------------------+----+------------+------------+
| LIXXX            | 31 | 2013-01-10 | 2013-01-03 |
+------------------+----+------------+------------+
1 rows in set

Now i tried this other query version, but the output is wrong: in my table i have 31 rows for Zn equal to LIXXX, why this query extract 51 rows?
Can you help me?
thank you.

mysql> SELECT
        zn,
	CURRENT_DATE () AS today,
	DATE_SUB(
		CURRENT_DATE (),
		INTERVAL 1 WEEK
	) AS WEEK,
	COUNT(
		IF (
			Day_of_the_event_s BETWEEN DATE_SUB(
				CURRENT_DATE (),
				INTERVAL 1 WEEK
			)
			AND CURRENT_DATE (),
			1,
			0
		)
	) AS `output`
FROM
	tbl_cc80
WHERE
	1
GROUP BY
	Zn,
	DATE_SUB(
		CURRENT_DATE (),
		INTERVAL 1 WEEK
	)
ORDER BY
	Day_of_the_event_s DESC;
+------------------+------------+------------+--------+
| zn               | today      | WEEK       | output |
+------------------+------------+------------+--------+
| LIXXX            | 2013-01-10 | 2013-01-03 |     51 |
+------------------+------------+------------+--------+
1 rows in set

your IF function decides whether to assign a 1 or a 0 based on the day, right?

so you have a bunch of 1’s and 0’s, and then you count them all

so no matter whether it’s a 1 or a 0, it’ll get counted

does this make sense?

no it no sense it’s true… You have right…
Changed this:

	
COUNT(
		IF (
			Day_of_the_event_s BETWEEN DATE_SUB(
				CURRENT_DATE (),
				INTERVAL 1 WEEK
			)
			AND CURRENT_DATE (),
			1,
			0
		)
	) AS `output`

to:


	COUNT(
		CASE
		WHEN Day_of_the_event_s BETWEEN DATE_SUB(
			CURRENT_DATE (),
			INTERVAL 1 WEEK
		)
		AND CURRENT_DATE () THEN
			1
		ELSE
			NULL
		END
	) AS `output`

Now the output is correct.
Thanks, I’ve learnt something today!

or to stick the horse’s nose in it; you’ve confused COUNT and SUM.