SQL语句:sum求和不能

山鬼谣007 2015-08-31 09:51:00
目标:根据compno ,相同则求和 想显示出locsum为 41707.7

上图是查询结果
下图是语句
SELECT
sinv_repmst.locsum as locsum,--------
sum(sinv_repmst.locsum) as sum,
ordermst.compno
FROM sinv_repmst,ordermst
WHERE sinv_repmst.compno='K1038-10' and ordermst.compno='K1038-10'

GROUP BY sinv_repmst.locsum, sinv_repmst.compno,ordermst.compno
实际情况还有许多复杂条件
...全文
322 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
山鬼谣007 2015-09-01
  • 打赏
  • 举报
回复
木有银?
无涯大者 2015-08-31
  • 打赏
  • 举报
回复
这种情况,可以在查询外头 套一层表试试!
gw6328 2015-08-31
  • 打赏
  • 举报
回复
SELECT sum(sinv_repmst.locsum) as sum, ordermst.compno FROM sinv_repmst,ordermst WHERE sinv_repmst.compno=ordermst.compno where sinv_repmst.compno='K1038-10' --这里只能是一对一的情况。 GROUP BY sinv_repmst.compno 你取两个表数据可能会有问题
山鬼谣007 2015-08-31
  • 打赏
  • 举报
回复
引用 2 楼 fengqingtao2008 的回复:
这种情况,可以在查询外头 套一层表试试!
------------------------------------ 怎么叫套一层,我菜鸟不懂
山鬼谣007 2015-08-31
  • 打赏
  • 举报
回复
引用 1 楼 jinfengyiye 的回复:
SELECT sum(sinv_repmst.locsum) as sum, ordermst.compno FROM sinv_repmst,ordermst WHERE sinv_repmst.compno=ordermst.compno where sinv_repmst.compno='K1038-10' --这里只能是一对一的情况。 GROUP BY sinv_repmst.compno 你取两个表数据可能会有问题
这个条件‘K1038-10’是因为数据太多,暂时加的,怪我没说明白

22,301

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧