导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

请问这个错在那里

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)
...全文
43 点赞 收藏 7
写回复
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'
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告