You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Oracle 11g多表关联查询需求:订单、订单项与产品表数据计算

Oracle 11g 订单统计查询实现

表结构与数据

order表

idstatusdate
1125-12-2022

orderitem表

idpidqtyUom(unit of measure)
11005KG
110110KG
110215KG

productstable表

pidpriceUom(unit of measure)
1001KG
1012KG
1023KG

期望输出

datequantityPrice
25-12-20223070

实现SQL语句

SELECT 
    o.date,
    SUM(oi.qty) AS quantity,
    SUM(oi.qty * p.price) AS Price
FROM 
    "order" o
JOIN 
    orderitem oi ON o.id = oi.id
JOIN 
    productstable p ON oi.pid = p.pid
GROUP BY 
    o.date;

语句说明

  • 通过JOIN关联三张表:order表与orderitem表通过订单ID关联,orderitem表与productstable表通过商品ID关联;
  • SUM(oi.qty)统计该订单下所有商品的总数量;
  • SUM(oi.qty * p.price)计算每个商品的金额(数量×单价)后求和,得到订单总金额;
  • 按订单日期o.date分组,确保每个订单日期对应一行统计结果。

内容的提问来源于stack exchange,提问作者Pearl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 09:20:41