Thursday, 8 August 2013

return queries result like two cols

return queries result like two cols

I have these two queries,
SELECT date(d1.date) AS date, d3.country_name AS country_name, COUNT(*) AS
male
FROM f1
INNER JOIN d1 ON f1.id_start_date = d1.id_start_date
INNER JOIN d2 ON f1.id_end_date = d2.id_end_date
INNER JOIN d3 ON f1.id_user = d3.id_user AND d3.gender = 'M'
GROUP BY date, country_name
ORDER BY country_name
SELECT date(d1.date) AS date, d3.country_name AS country_name, COUNT(*) AS
female
FROM f1
INNER JOIN d1 ON f1.id_start_date = d1.id_start_date
INNER JOIN d2 ON f1.id_end_date = d2.id_end_date
INNER JOIN d3 ON f1.id_user = d3.id_user AND d3.gender = 'F'
GROUP BY date, country_name
ORDER BY country_name
that return me something like this:
date, country, male
2009-01-01, Spain, 34
and
date, country, female
2009-01-01, Spain, 12
but I need a query that return me this:
date, country, male, female
Any suggestion?

No comments:

Post a Comment