首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

这个SQL语句应该怎么写

2012-03-03 
这个SQL语句应该如何写?想达到这个效果,select a.pid,a.scmid,a.productmodel,a.amountin,sum( b.AmountIn

这个SQL语句应该如何写?
想达到这个效果,
select a.pid,a.scmid,a.productmodel,a.amountin,sum( b.AmountIn)as num1 
from Product_Stock a, Product_In b
where a.scmid=b.scmid

运行提示
服务器: 消息 8120,级别 16,状态 1,行 1
列 'a.Pid' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
服务器: 消息 8120,级别 16,状态 1,行 1
列 'a.ProductModel' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
服务器: 消息 8120,级别 16,状态 1,行 1
列 'a.AmountIn' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。

应该如何写啊?谢谢了

[解决办法]
少了GROUP BY 子句:
select a.pid,a.scmid,a.productmodel,a.amountin,sum( b.AmountIn)as num1
from Product_Stock a, Product_In b 
where a.scmid=b.scmid group by a.pid,a.scmid,a.productmodel,a.amountin
按你的要求自己改就可以了

热点排行