0
我有一個產生一個結果集的SQL查詢結果每種類型的記錄數,如下圖所示:如何獲得在設置
(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
我不知道是否有可能返回所有的簡單計數對於第一列中的每個值,等於第一列中的某個值的記錄。總的來說,我預計在第一列中有6個唯一值,但它在查詢執行之間可能會有所不同。
這不就是'group by'SQL語句的原因嗎?如下所示:「將GROUP BY dv.venue添加到您的SQL語句的末尾,並將語句的選擇部分更改爲'dv.venue,count(*)'? – Slartibartfast
我試圖計算所有在第一列中記錄第一列中每個唯一值作爲我的最終結果集 –