Skip to content
Advertisement

Counting Number of Males/females within a blood group

So I have two Data Tables ‘DONOR’ AND ‘ACCEPTOR’. Each have the following schema:

I’m trying to create a query to output the Gender and Blood Group (BG) as well as a Count for that Gender+Blood Group to do this I created the following query which is kind of correct but I only want it to output each Gender+Blood Group once with the total count which i don’t exactly understand how to do (I’m learning SQL and I figured out how to get this query and union it but not make it so each Gender + Blood Group only outputs once)

My Query:

Example Output:

My Output:

Advertisement

Answer

To get what you want, you will have to use a subquery:

Note I removed DISTINCT because it was superfluous. The GROUP BY is already sure to return only one row per distinct GENDER, BG pair in each query.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement