开发者

How to get count for each type of record in a result set

I have a SQL query that produces a result set as shown below:

(SELECT dv.venue as venue, pglr.users_oauth_uid as user_id, pgl.date as guest_list_date
    FROM promoters_guest_lists pgl
    JOIN users_promoters_guest_list_authorizations upgla 
    ON pgl.users_promoters_guest_list_authorizations_id = upgla.id
    JOIN promoters_guest_lists_reservations pglr
    ON pgl.id = pglr.promoters_guest_lists_id
    JOIN promoters_venues pv
    ON pv.id = upgla.promoters_venues_id
    JOIN data_venues dv
    ON dv.id = pv.venue_id
    WHERE upgla.deactivated = 0)

    UNION ALL

    (SELECT dv.venue as venue, pglre.oauth_uid as user_id, pgl.date as guest_list_date
    FROM promoters_guest_lists pgl
    JOIN users_promoters_guest_list_authorizations upgla 
    ON pgl.users_promoters_guest_list_authorizations_id = upgla.id
    JOIN promoters_guest_lists_reservations pglr
    ON pgl.id = pglr.promoters_guest_lists_id
    JOIN promoters_guest_lists_reservations_entourages pglre
    ON pglr.id = pglre.promoters_guest_lists_reservations_id
    JOIN promoters_venues pv
    ON pv.id = upgla.promoters_venues_id
    JOIN data_venues dv
    ON dv.id = pv.venue_id
    WHERE upgla.deactivated = 0)
    ORDER BY 1

Estate  504405294   2011-08-30
Estate  504405294   2011-09-20
Estate  504405294   2011-09-19
Estate  504677586   2011-08-30
Estate  100002624783324 2011-08-30
Estate  100002624783324 2011-09-20
Estate  1451950133  2011-09-19
Estate  1634269784  2011-09-19
Estate  100002624783324 2011-09-19
Royale  504405294   2011-08-28
Royale  504405294   2011-09-04
Royale  100002624783324 2011-08-28
Royale  1634269784  2011-09-04

I'm wondering if it's possible to return simple counts of all the records that equal a certain value in the first column, for every value in the first 开发者_如何学编程column. In total I anticipate 6 unique values in the first column, but it can vary between query executions.


SELECT venue, COUNT(*) FROM (YOUR_QUERY_HERE) t GROUP BY t.venue;

that's all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜