Wednesday, November 25, 2009

Sample oracle query

Table -> innings_runs (id Number, runs Number)

What to do : Select player ids who have made more than
100 runs without ever making 50 runs in a single innings.

ID RUNS
---------- ----------
1 48
1 48
1 48
2 50
2 51


select distinct(id) from innings_runs
where id in
(select id from (select id,sum(runs) as sum1 from innings_runs group by id having(sum(runs) > 100)))
and runs < 50
;

No comments:

Blog Archive