select top 3 mdg,qsg,count(mdg) cont from HxTable
where Qsg ='青岛' group by mdg,qsg
order by count(mdg) desc
union all
select top 2 mdg,qsg,count(mdg) cont from HxTable
where Qsg ='宁波' group by mdg,qsg
order by count(mdg) desc
union all
select top 3 mdg,qsg,count(mdg) cont from HxTable
where Qsg ='上海' group by mdg,qsg
order by count(mdg) desc
消息 156,级别 15,状态 1,第 6 行
关键字 'union' 附近有语法错误。
消息 156,级别 15,状态 1,第 11 行
关键字 'union' 附近有语法错误。
如果要排序可咋办呢
请教大师,一个条件查询,但是有错误,应该怎么办呢
答案:4 悬赏:0 手机版
解决时间 2021-04-05 15:24
- 提问者网友:不爱我么
- 2021-04-05 11:01
最佳答案
- 五星知识达人网友:从此江山别
- 2021-04-05 12:25
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
可以做成子查询,
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
可以做成子查询,
全部回答
- 1楼网友:怀裏藏嬌
- 2021-04-05 15:28
大哥你这不错 我自杀 集合 可以跟where 一起用么你老师没教你啊 group by 是跟 hvaing一起用不能跟 where 一起用
- 2楼网友:醉吻情书
- 2021-04-05 14:57
select * from
(select top 3 mdg,qsg,count(mdg) cont from HxTable
where Qsg ='青岛' group by mdg,qsg
union all
select top 2 mdg,qsg,count(mdg) cont from HxTable
where Qsg ='宁波' group by mdg,qsg
union all
select top 3 mdg,qsg,count(mdg) cont from HxTable
where Qsg ='上海' group by mdg,qsg
)
order by count(mdg) desc
- 3楼网友:执傲
- 2021-04-05 13:57
不可能
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯