SQL 获取利润最少的日期
SQL get the date with the least profit made
目前我正在查询以获取利润最少的日期。我为此使用的 table 是这个:
我想出的查询找到利润最少的日期,但没有显示当天赚取的金额的总和:
SELECT MIN(PRICE*QUANTITY) AS UMSATZ, ORDER_DATE
FROM FACT_ORDER
GROUP BY ORDER_DATE
ORDER BY UMSATZ
LIMIT 1;
所以结果是:
哪个查询可以额外显示当天盈利的SUM金额(不加一列)?非常感谢您!
Which query could show the SUM amount of the profit made that day in addition (not with an additional column)?
总计:
SELECT DISTINCT ORDER_DATE,
SUM(PRICE*QUANTITY) OVER(PARTITION BY ORDER_DATE) AS UMSATZ
FROM FACT_ORDER
QUALIFY (PRICE*QUANTITY) = MIN(PRICE*QUANTITY) OVER(PARTITION BY ORDER_DATE);
您可以通过自联接实现此目的。
select umsatz, a.order_date, sumUmsatz from (
select
min(price*quantity) as umsatz, order_date
from FACT_ORDER
group by datum order by min(price*quantity)asc
)a inner join (
select sum(price*quantity) as sumUmsatz, order_date from
FACT_ORDER group by order_date
) b on a.order_date = b.order_date
where rownum = 1;
目前我正在查询以获取利润最少的日期。我为此使用的 table 是这个:
我想出的查询找到利润最少的日期,但没有显示当天赚取的金额的总和:
SELECT MIN(PRICE*QUANTITY) AS UMSATZ, ORDER_DATE
FROM FACT_ORDER
GROUP BY ORDER_DATE
ORDER BY UMSATZ
LIMIT 1;
所以结果是:
哪个查询可以额外显示当天盈利的SUM金额(不加一列)?非常感谢您!
Which query could show the SUM amount of the profit made that day in addition (not with an additional column)?
总计:
SELECT DISTINCT ORDER_DATE,
SUM(PRICE*QUANTITY) OVER(PARTITION BY ORDER_DATE) AS UMSATZ
FROM FACT_ORDER
QUALIFY (PRICE*QUANTITY) = MIN(PRICE*QUANTITY) OVER(PARTITION BY ORDER_DATE);
您可以通过自联接实现此目的。
select umsatz, a.order_date, sumUmsatz from (
select
min(price*quantity) as umsatz, order_date
from FACT_ORDER
group by datum order by min(price*quantity)asc
)a inner join (
select sum(price*quantity) as sumUmsatz, order_date from
FACT_ORDER group by order_date
) b on a.order_date = b.order_date
where rownum = 1;