sql - I need make a subquery -
i have 2 tables: invitations , events.
i need name of event, total of guest per event , total of presents when true per event in same query!
something join both tables (left join) selecting events.name, count(invitations.guest), count(invitations.presents when = true) , group events...
looking tables data...
i think work don't want...
select e.name, count(in.guest) guests, (select count(presents) watermelon.invitations presents = true) presents watermelon.events e left join watermelon.invitations in on e.id = in.event group in.event;
then get:
http://dl.dropbox.com/u/360112/duda/resultado.jpg
some suggestion? please need it, , i'm tired of trying , getting wrong results... in advance!
sounds want using count
, group by
, case
:
select e.id, e.name, count(i.id) totalguests, count(case when i.presents = 'true' 1 end) totalpresents events e left join invitations on e.id = i.event group e.id, e.name
i'm not positive data type of presents, should close. using left join
return events.
Comments
Post a Comment