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

这句查询哪里错了
select InnerID ,PositionX, PositionY, PositionZ, RotationX, RotationY, RotationZ, SizeX, SizeY, SizeZ, ComponentType, (a1.InnerID,sum (a1.ComponentValues) as Diameter,sum(a2.ComponentValues) as cuttingLength )
from ((AnormalComponentInfo a1, a2 inner join ComponentInfo c on a1.InnerID = c.InnerID )inner join Template t on c.TemplateID = t.TemplateID ) 
where c.ParentComponentID='A132D0AB-8A40-4204-B48B-124EF0B98A64' and a1.InnerID = a2.InnerID and a1.ComponentAttribute = 'Diameter' and a2.ComponentAttribute = 'cuttingLength'
group by a1.InnerID

------解决方案--------------------
SQL code
select InnerID ,PositionX, PositionY, PositionZ, RotationX, RotationY, RotationZ, SizeX, SizeY, SizeZ, ComponentType,  --这些列都没有指定表
(a1.InnerID,sum (a1.ComponentValues) as Diameter,sum(a2.ComponentValues) as cuttingLength    )  
from ((AnormalComponentInfo a1, a2            
inner join ComponentInfo c on a1.InnerID = c.InnerID )
inner join Template t on c.TemplateID = t.TemplateID )  
where c.ParentComponentID='A132D0AB-8A40-4204-B48B-124EF0B98A64' 
and a1.InnerID = a2.InnerID 
and a1.ComponentAttribute = 'Diameter' 
and a2.ComponentAttribute = 'cuttingLength'
group by a1.InnerID       --聚合列于获取的信息列不匹配

------解决方案--------------------
所有未使用聚合函数的列必须出现在group by 后面。也就是你select的这些列PositionX, PositionY, PositionZ, RotationX, RotationY, RotationZ, SizeX, SizeY, SizeZ, ComponentType都必须出现在group by 后面