help~~~~~~~~~

heeh 2001-11-28 04:13:15
select top 1 'a' as I ,C,min(D) as D from test where I='a' and D is not null group by C order by D
union all
select top 1 'b' as I ,C,min(D)as D from test where I='b' and D is not null group by C order by D

error:
服务器: 消息 156,级别 15,状态 1,行 2
在关键字 'union' 附近有语法错误。

为什么不能union ,向高手请教
...全文
67 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
heeh 2001-11-28
  • 打赏
  • 举报
回复
谢谢ragweed_wg(冷月一刀) 的提醒
虽然你的解答也错了,但我丛中找到了答案:)
我会给分的
ragweed_wg 2001-11-28
  • 打赏
  • 举报
回复
union时,不能对每一个子集做order by,
select I,C,D
from
(select top 1 'a' as I ,C,min(D) as D from test where I='a' and D is not null)
union all
(select top 1 'b' as I ,C,min(D)as D from test where I='b' and D is not null) group by C
order by D
heeh 2001-11-28
  • 打赏
  • 举报
回复
可是单句能出来的
select top 1 'a' as I ,C,min(D) as D from test where I='a' and D is not null group by C order by D
有结果的
麻烦再想一想
用其他方法可以解决的但我希望一个语句出来结果
heeh 2001-11-28
  • 打赏
  • 举报
回复
有人吗
高手~~~~~~~~~
UP
IronPromises 2001-11-28
  • 打赏
  • 举报
回复
SQL语句是先检测
Where后面的内容.

因此在别名D出来之前
order by D
被认为是不合法的.

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧