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...

https://dl.dropbox.com/u/360112/duda/invitaciones.jpg https://dl.dropbox.com/u/360112/duda/eventos.jpg

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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -