sql语句的问题!

king0401 2003-08-29 11:32:50
table1(a1,a2,a3)
table2(a1,a2,a3)


select distinct a1,a2,sum(a3) from
(select a1,a2,a3 from table1
union all select a1,a2,a3
from table1)
group by a1,a2
...全文
45 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyy431706 2003-08-29
  • 打赏
  • 举报
回复
GZ
king0401 2003-08-29
  • 打赏
  • 举报
回复
谢谢大家
dafu71 2003-08-29
  • 打赏
  • 举报
回复
select a1,a2,sum(a3) from
(select a1,a2,a3 from table1
union all select a1,a2,a3
from table1) as aa
group by a1,a2
aierong 2003-08-29
  • 打赏
  • 举报
回复
select a1,t.a2,sum(t.a3) from
(select a1,a2,a3 from table1
union all
select a1,a2,a3 from table2) as t
group by t.a1
aierong 2003-08-29
  • 打赏
  • 举报
回复

你意思是把2个表合并为一个表,再找出a3列的最大项目对应的不同记录吗
txlicenhe 2003-08-29
  • 打赏
  • 举报
回复
select a1,a2,sum(a3) from -- distinct 不必要吧?
(select a1,a2,a3 from table1
union all select a1,a2,a3
from table1) tmp -- 指定一个别名
group by a1,a2
txlicenhe 2003-08-29
  • 打赏
  • 举报
回复
select distinct a1,a2,sum(a3) from
(select a1,a2,a3 from table1
union all select a1,a2,a3
from table1) tmp -- 指定一个别名
group by a1,a2
king0401 2003-08-29
  • 打赏
  • 举报
回复
这样写会报错误:在关键字 'group' 附近有语法错误。

有什么解决方法?

34,874

社区成员

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

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