SQL语句如何将两个表格的数据合并查询出来,然后求某个字段对应另外一个数据字段的和,急急急
两个表格通过FItemID连接查询(查询的结果为每个Fitem都有好几个期初数据),然后求Fitem对应期初数据的和,selectt6.FItemIDas物料代码,t5....
两个表格通过FItemID连接查询(查询的结果为每个Fitem都有好几个期初数据),然后求Fitem对应期初数据的和,
select t6.FItemID as 物料代码,
t5.FPeriod as 期初取数期间,
sum(t5.FBegQty) as 期初数据
from ICInvBal t5 inner join t_ICItem t6 on t6.FItemID=t5.FItemID
where t5.FPeriod=9
and t5.FItemID=260
order by t5.FItemID
运行时出现错误:
消息 8120,级别 16,状态 1,第 2 行
选择列表中的列 't_ICItem.FItemID' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中 展开
select t6.FItemID as 物料代码,
t5.FPeriod as 期初取数期间,
sum(t5.FBegQty) as 期初数据
from ICInvBal t5 inner join t_ICItem t6 on t6.FItemID=t5.FItemID
where t5.FPeriod=9
and t5.FItemID=260
order by t5.FItemID
运行时出现错误:
消息 8120,级别 16,状态 1,第 2 行
选择列表中的列 't_ICItem.FItemID' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中 展开
展开全部
用sum的话必须要加group by,所有非聚合函数都要出现在group by 列
select t6.FItemID as 物料代码,
t5.FPeriod as 期初取数期间,
sum(t5.FBegQty) as 期初数据
from ICInvBal t5 inner join t_ICItem t6 on t6.FItemID=t5.FItemID
where t5.FPeriod=9
and t5.FItemID=260
GROUP BY t6.FItemID, t5.FPeriod
order by t5.FItemID
select t6.FItemID as 物料代码,
t5.FPeriod as 期初取数期间,
sum(t5.FBegQty) as 期初数据
from ICInvBal t5 inner join t_ICItem t6 on t6.FItemID=t5.FItemID
where t5.FPeriod=9
and t5.FItemID=260
GROUP BY t6.FItemID, t5.FPeriod
order by t5.FItemID
展开全部
select t6.FItemID as 物料代码,
t5.FPeriod as 期初取数期间,
sum(t5.FBegQty) as 期初数据
from ICInvBal t5 inner join t_ICItem t6 on t6.FItemID=t5.FItemID
where t5.FPeriod=9
and t5.FItemID=260 group by t6.FItemID,t5.FPeriod
order by t5.FItemID
t5.FPeriod as 期初取数期间,
sum(t5.FBegQty) as 期初数据
from ICInvBal t5 inner join t_ICItem t6 on t6.FItemID=t5.FItemID
where t5.FPeriod=9
and t5.FItemID=260 group by t6.FItemID,t5.FPeriod
order by t5.FItemID
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询