连接两个表,从多个零件号中获取总和

发布于 2025-01-19 10:57:44 字数 1000 浏览 1 评论 0原文

首先,我试图为连接的表格获得一笔款项。我可以加入桌子并缩小零件的范围,但有2行。我知道这需要一个嵌入式查询,但是将我的头放在一起。这加入了两个表以显示零件号“ AC01151507NANA”的数量。我要做的是总QTY_ORDEREDERDED,该案例显示了1和2,但我需要3个总和,因为还有其他零件的计数要大得多。此外,大约有100个零件号。有没有办法在此处显示所有零件号,还是一个一个一个零件号?

SELECT oeordlin_sql.item_no, oeordlin_sql.qty_ordered, oeordlin_sql.ord_no, oeordlin_sql.item_no, oeordhdr_sql.ord_type, oeordhdr_sql.status, oeordhdr_sql.ord_type
FROM oeordlin_sql
INNER JOIN oeordhdr_sql ON oeordlin_sql.ord_no=oeordhdr_sql.ord_no
WHERE oeordhdr_sql.ord_type != 'Q' AND oeordhdr_sql.status != 'L'
AND item_no = 'AC011507NANA';

在David的帮助下,我得到了适当的显示。但是,我有100多个零件号。如上所述,是否有一种方法可以查找所有内容并拥有项目列表?如果没有,我只会一个人与这里的东西一起去。

First, I'm trying to get a sum for the joined tables. I can join the tables and narrow down the part but there are 2 lines. I know this requires an embedded query but scratching my head on putting it together. This joins the two tables to show the quantity for part number "AC011507NANA". What I'm trying to do is there the total qty_ordered which is this case show 1 and 2 but I need the sum of 3 as there are other parts with much larger counts. In addition, there are about 100 part numbers. Is there a way to display insert all the part numbers here or is it only one by one?

SELECT oeordlin_sql.item_no, oeordlin_sql.qty_ordered, oeordlin_sql.ord_no, oeordlin_sql.item_no, oeordhdr_sql.ord_type, oeordhdr_sql.status, oeordhdr_sql.ord_type
FROM oeordlin_sql
INNER JOIN oeordhdr_sql ON oeordlin_sql.ord_no=oeordhdr_sql.ord_no
WHERE oeordhdr_sql.ord_type != 'Q' AND oeordhdr_sql.status != 'L'
AND item_no = 'AC011507NANA';

enter image description here

With David's help I got the proper display. However, I have over 100 part numbers. As mentioned above, is there a way to look up all of them and have the list of items? If not, I'll just go one by one with what I have here.

Item Totals

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎无痕… 2025-01-26 10:57:44

您几乎已经完成了所有工作,您需要实现的只是 sum() 和 group by。

SELECT oeordlin_sql.item_no, sum(oeordlin_sql.qty_ordered) as total
FROM oeordlin_sql
INNER JOIN oeordhdr_sql ON oeordlin_sql.ord_no=oeordhdr_sql.ord_no
WHERE oeordhdr_sql.ord_type != 'Q' AND oeordhdr_sql.status != 'L'
AND item_no = 'AC011507NANA'
GROUP BY oeordlin_sql.item_no;

这将返回 item_no 和 qty_ordered 总数。
希望这就是您正在寻找的

You have almost all the job done, all you need to implement is a sum() and group by.

SELECT oeordlin_sql.item_no, sum(oeordlin_sql.qty_ordered) as total
FROM oeordlin_sql
INNER JOIN oeordhdr_sql ON oeordlin_sql.ord_no=oeordhdr_sql.ord_no
WHERE oeordhdr_sql.ord_type != 'Q' AND oeordhdr_sql.status != 'L'
AND item_no = 'AC011507NANA'
GROUP BY oeordlin_sql.item_no;

This will return the item_no and the total of the qty_ordered.
Hope this is what you were looking for

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文