日期:2014-05-17  浏览次数:20295 次

嵌套查询 Group By 语句问题
类似这样的语句:

  Select * From ( Select b.code as 编码,b.style as 类型,a.time as 时间 From (select ...) a,(select...) b where a.flag = b.flag ) c  Group by c.编码,c.类型

这样的语句 一直提示 b.code 不在Group by 中,这要怎么修改啊?
sql

------解决方案--------------------

select a.code as 编码,a.quantity as 数量,b.time as 时间    from (select * From table1) a, (select * From table2) b  where a.flag=b.flag
可以替换为
select a.code as 编码,a.quantity as 数量,b.time as 时间
from table1 a,table2 b
where a.flag=b.flag
所以你9楼的语句可以替换为
select a.code as [编码],b.time as [时间],sum(a.quantity) as [数量] 
from table1 a,table2 b 
where a.flag=b.flag
group by a.code,b.time

------解决方案--------------------
select a.code 编码,a.quantity 数量,b.time 时间 From 
(select code ,sum(quantity) as quantity from tb1 group by code)a,tb2 b where a.flag=b.flag