Her er en mulighed ved at bruge en underforespørgsel med DISTINCT
:
SELECT COUNT(*) gender_count,
SUM(IF(gender='male',1,0)) male_count,
SUM(IF(gender='female',1,0)) female_count
FROM (
SELECT DISTINCT tel, gender
FROM example_dataset
) t
Dette vil også fungere, hvis du ikke ønsker at bruge en underforespørgsel:
SELECT COUNT(DISTINCT tel) gender_count,
COUNT(DISTINCT CASE WHEN gender = 'male' THEN tel END) male_count,
COUNT(DISTINCT CASE WHEN gender = 'female' THEN tel END) female_count
FROM example_dataset