请问这个错在那里

qq68435700 2008-01-23 12:27:29
select orderid,sum(unitprice*quantity) from
(select orderid,sum(unitprice*quantity)
from orderdetails
group by orderid) a
where orderid='10246'
错误提球为:没有为第 2 列(属于 'a')指定列。

意思是先查询出
select orderid,sum(unitprice*quantity)
from orderdetails
group by orderid
然后在通过子查询想查出orderid='10246'的orderid,sum(unitprice*quantity)
...全文
120 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
中国风 2008-01-23
  • 打赏
  • 举报
回复
select orderid,合计 from
(select orderid,sum(unitprice*quantity) as 合计 --少了一个别名,内联视图必须有列名
from orderdetails
group by orderid) a
where orderid='10246'
wyb0026 2008-01-23
  • 打赏
  • 举报
回复
不用费二遍事直接 不行吗?而且效率非常差

select orderid,sum(unitprice*quantity) from
from orderdetails
where orderid='10246'

你实在坚持应该这样写

select orderid,sum(amunt) from
(select orderid,sum(unitprice*quantity) amunt
from orderdetails
group by orderid) as a
where orderid='10246'
loworth 2008-01-23
  • 打赏
  • 举报
回复
改法2把group by 写到子查询里
loworth 2008-01-23
  • 打赏
  • 举报
回复
[CODE=SQL]
/*改法1*/
select orderid,sum(unitprice*quantity) from
(select orderid,unitprice,quantity
from orderdetails
) a
where orderid='10246'
group by orderid
/*改法2*/
select orderid,acount from
(select orderid,SUM(unitprice*quantity) AS acount
from orderdetails
) a
where orderid='10246'
group by orderid
/*改法3*/
select orderid,sum(unitprice*quantity)
from orderdetails
where orderid='10246'
group by orderid
[/CODE]
JL99000 2008-01-23
  • 打赏
  • 举报
回复
select a.orderid,a.ZH from
(select orderid,sum(unitprice*quantity) as ZH
from orderdetails
group by orderid) a
where a.orderid='10246'

接分了
ORARichard 2008-01-23
  • 打赏
  • 举报
回复

select orderid,sum(unitprice*quantity) amount
from orderdetails
where orderid='10246'
group by orderid
tim_spac 2008-01-23
  • 打赏
  • 举报
回复

select orderid,amount
from (
select orderid,amount=sum(unitprice*quantity)
from orderdetails
group by orderid) a
where orderid='10246'

34,838

社区成员

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

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