连接两个表,从多个零件号中获取总和
首先,我试图为连接的表格获得一笔款项。我可以加入桌子并缩小零件的范围,但有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';
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您几乎已经完成了所有工作,您需要实现的只是 sum() 和 group by。
这将返回 item_no 和 qty_ordered 总数。
希望这就是您正在寻找的
You have almost all the job done, all you need to implement is a sum() and group by.
This will return the item_no and the total of the qty_ordered.
Hope this is what you were looking for