我有以下代码:
SELECT
day
,product_id
,product_name
,quantity_on_hand
,inventory_condition
FROM
(
SELECT
table1.product_id as product_id
,table1.product_name as product_name
FROM table1
WHERE
product_id = XXXX
)product_table
,
(
SELECT
table2.day as day
,table2.product_id as inv_product_id
,inventory_condition
,sum( table2.quantity) AS quantity_on_hand
FROM table2
WHERE
table2.day = TO_DATE('{RUN_DATE_YYYY/MM/DD}', 'YYYY/MM/DD')
AND table2.inventory_condition = XXX
GROUP BY
table2.day
,table2.product_id
,inventory_conditio
) inv
WHERE
product_id = inv.product_id
如果我想提取一天的数据,这段代码效果很好。但我想在同一个查询中提取3天不同的数据。我已经尝试在table2.day上使用OR(),但是它会在3天内总计给出3天的数据总和。我也尝试过做
Sum() over (Partition by table2.day)
但我不确定如何使用语法。
非常感谢你的帮助