萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mssql數據庫 >> SQL語句查詢重復字段並按數量排序

SQL語句查詢重復字段並按數量排序

   SQL語句

  描述:exhibitiononline表主鍵exhiid, exhibitor表有外鍵 exhid,對應表 exhibitiononline的主鍵exhiid;

  exhibitiononline表---------> 一對多 <------------- exhibitor表

  功能:查詢出 exhibitiononline表中,exhiid存在於表 exhibitor中的所有數據,並根據 exhibitor表的exhid的數量排序

  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

copyright © 萬盛學電腦網 all rights reserved