"Robert Citek" <robert.ci...@gmail.com>
wrote in message
news:4145b6790901072206u73b367f1g3d377bb6962de...@mail.gmail.com
> How can I construction a SQL query to pick the top three (3) items in
> a group?
>
> I have a list of sports teams which are grouped into divisions, say A,
> B, C, D, etc.  At the end of the season I would like to get a list of
> the top three teams (those with the most wins) in each division.  If I
> wanted the best team from each division, I could write this:
>
> select div, team, max(wins) from teams group by div ;

select div, team from teams t1 where rowid in
(select rowid from teams t2 where t1.div = t2.div
 order by wins desc limit 3);

Igor Tandetnik



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to