日期:2014-05-19  浏览次数:20494 次

问一个复杂的SQL语句,不是高手不要进哦!
问一个复杂的SQL语句
string   strSel1   =   "select   top   20   distinct   w_lx   from   wz_lx   order   by   (select   count(*)   from   wz   where   wz.w_lx   =   wz_lx.w_lx   )   desc ";
---------------------------------
1、要求只列出20个
2、要w_lx不重复
3、要按w_lx的数目从大到小排序
-----------------------------
有没有人知道怎么写呀???

------解决方案--------------------
不是高手可以吗?

Select top 20 wz_lx.w_lx as w_lx, Count(wz.w_lx) as wzCount
From wz_lx, wz
Where wz_lx.w_lx=wz.w_lx
Group by w_lx
Order by wzCount
------解决方案--------------------
Select top 20 wz_lx.w_lx as w_lx, Count(distinct wz.w_lx) as wzCount
From wz_lx, wz
Where wz_lx.w_lx=wz.w_lx
Order by wzCount desc