SQL語句查詢重復(fù)字段并按數(shù)量排序

字號:


    SQL語句
    描述:exhibitiononline表主鍵exhiid, exhibitor表有外鍵 exhid,對應(yīng)表 exhibitiononline的主鍵exhiid;
    exhibitiononline表---------> 一對多 <------------- exhibitor表
    功能:查詢出 exhibitiononline表中,exhiid存在于表 exhibitor中的所有數(shù)據(jù),并根據(jù) exhibitor表的exhid的數(shù)量排序
    select * from exhibitiononline join
    (select exhid,count(exhid) as s from exhibitor group by exhid) as t
    on exhibitiononline.exhiid=t.exhid
    order by t.s desc