sorry, darkeye, that won't work
it's a cross-join and will grossly inflate the totals -- i tested it
try this instead --
Code:
select p1.pilot_id, pilot_name
, count(*) as matches
, sum(match_win) as wins
from pilot p1, metch m1
where p1.pilot_id = m1.pilot_id
group by p1.pilot_id, pilot_name
note that it depends on match_win=1 being "summable" (i made that word up)
if match_win were something else, you could use a case structure to achieve the same thing --
Code:
select p1.pilot_id, pilot_name
, count(*) as matches
, sum(
case when match_win='y'
then 1 else 0
end ) as wins
from pilot p1, metch m1
where p1.pilot_id = m1.pilot_id
group by p1.pilot_id, pilot_name
p.s. i used "metch" as the table name because "match" is a reserved word
Bookmarks