Finding ratio based on count in Oracle SQL -


i'm trying list each teams ratio of matches lost total matches played.

i've tried following doesn't seem work:

select teams.name name, lost teams join matches on teams.name in (matches.home, matches.away) group teams.name having (1 - (matches.winner / (count (matches.home) + count (matches.away)))) lost; 

is problem way wrote function in last line?

relational diagram reference:

enter image description here

the having clause used filter resultset after grouping has occured, not define functions. need write logic columns need returned within select clause.

select  t.name         ,count(m.*) matches_played         ,sum(case when m.winner = t.name 1 else 0 end) wins         ,sum(case when m.winner = t.name 0 else 1 end) losses         ,sum(case when m.winner = t.name 1 else 0 end)/count(m.*) win_percent         ,sum(case when m.winner = t.name 0 else 1 end)/count(m.*) loss_percent    teams t inner join         matches m on      t.name = m.home or      t.name = m.away         group         t.name 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -