yoda
yoda

Reputation: 569

Get the count of group by results

I am getting count of some column by using group by. It returns results of the form,

col1 count

date1 1

date2 2

I would like to further count on this result so that it returns 3.

How would I go about accomplishing this?

SELECT t.p_date
,count(t.p_date) AS saturday
FROM t_p_booking t
WHERE t.p_id IN (
    220
    ,221
    )
AND dayofweek(t.p_date) = 7
AND date_format(t.p_date, '%Y%m') = : ccyymm
GROUP BY t.p_date

Upvotes: 0

Views: 84

Answers (2)

BitWise
BitWise

Reputation: 78

Would that not just be:

SELECT count(*)
FROM t_p_booking t
WHERE t.p_id IN (
    220
    ,221
    )
AND dayofweek(t.p_date) = 7
AND date_format(t.p_date, '%Y%m') = : ccyymm
GROUP BY t.p_date

Upvotes: 2

gvee
gvee

Reputation: 17161

Add WITH ROLLUP to the end of your GROUP BY clause

Upvotes: 2

Related Questions