さかもつ備忘録

Monday, April 09, 2007

MySQLランキング表示

MySQLの場合テーブルJOINしてがんばる。

select r.*, if(n.Count is null, 0, count(*)) + 1 as Rank
from tableA r left join tableA n on (r.type=n.type) and (r.Count < n.Count)
where r.type='A'
group by r.ItemCd
order by a.Count desc;

0 Comments:

Post a Comment

<< Home