SQL ORACLE 求和函数

萨拉赫-埃丁·罗阿尔米

大家好,我的代码有问题,它给了我三个多输出,而我需要一行,其中包含总树数和总价格

--------------我的代码--------------

  • SELECT A3_ORDER_ITEM.ORDER_ID,A3_ORDER_ITEM.QUANTITY AS “树的数量”,A3_ORDER_ITEM.QUANTITY * A3_TREE.PRICE AS “价格” FROM A3_CUSTOMER INNER JOIN A3_ORDER_FORM ON A3_ORDER_FORM.CUSTOMER_ID = A3_CUSTOMER.CUSTOMER_ID INNER JOIN A3_ORDER_ITEM ON A3_ORDER_ITEM.ORDER_ID = A3_ORDER_FORM.ORDER_ID在 A3_TREE.ID=A3_ORDER_ITEM.TREE_ID 上 A3_TREE 内部连接 ​​A3_ORDER_ITEM.ORDER_ID = '00000072';

---------------输出----------------------------输出

大力水手

您需要聚合查询:

SELECT A3_ORDER_ITEM.ORDER_ID ,
       sum(A3_ORDER_ITEM.QUANTITY) AS "Number of Trees",  
       Sum(A3_ORDER_ITEM.QUANTITY*A3_TREE.PRICE) AS "PRICE"
  FROM A3_CUSTOMER 
 INNER JOIN A3_ORDER_FORM ON A3_ORDER_FORM.CUSTOMER_ID=A3_CUSTOMER.CUSTOMER_ID 
 INNER JOIN A3_ORDER_ITEM ON A3_ORDER_ITEM.ORDER_ID=A3_ORDER_FORM.ORDER_ID
 INNER JOIN A3_TREE ON A3_TREE.ID=A3_ORDER_ITEM.TREE_ID 
 WHERE A3_ORDER_ITEM.ORDER_ID = '00000072'
Group by A3_ORDER_ITEM.ORDER_ID;

此查询也适用于多个A3_ORDER_ITEM.ORDER_ID它会给每一个记录A3_ORDER_ITEM.ORDER_ID

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章