sql count排序的语句

select distinct cip ,cs_Referer from logdb
order by (select count(distinct cs_Referer) where cip ='66.249.70.230') desc 该怎么修改

Count排序语法如下:
Select * from (Select Count(字段名) as 别名 from 表名 Group By 字段名) as [查询1] order by [查询1].字段
Count语句不支持where和order by,把他先整理成一个查询,再去排列筛选就好了。
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-05-25
select distinct cip ,cs_Referer,count(distinct cs_Referer) col from logdb where cip ='66.249.70.230' order by col desc本回答被提问者采纳
第2个回答  2015-05-20
select a,b,count(b) as x
from test
where a=0
group by a,b

having count(b)>=1

order by count(b)本回答被网友采纳
第3个回答  2011-05-24

select * from (
select * from (
select top 3 mdg,qsg,count(mdg) cont from HxTable
where Qsg ='青岛' group by mdg,qsg
order by count(mdg) desc)t1
union all

select * from(
select top 2 mdg,qsg,count(mdg) cont from HxTable
where Qsg ='宁波' group by mdg,qsg
order by count(mdg) desc)t2
union all

select * from (
select top 3 mdg,qsg,count(mdg) cont from HxTable
where Qsg ='上海' group by mdg,qsg
order by count(mdg) desc)t3
) as result
order by cont desc
相似回答