arcs / tasks /readable /008 /task_readable.md
yanlinf's picture
Release ARCS dataset
1fb4e2d verified
|
Raw History Blame Contribute Delete
847 Bytes

Task: 008

Database: retails

Question

Identify the manufacturer that contributed the highest profit during the last quarter of 1994. Show the manufacturer and the profit.

Gold Query

WITH manufacturer_profit AS (
SELECT p.p_mfgr,
SUM(l.l_extendedprice * (1 - l.l_discount) - ps.ps_supplycost * l.l_quantity) AS profit
FROM lineitem l
JOIN part p ON l.l_partkey = p.p_partkey
JOIN partsupp ps ON l.l_partkey = ps.ps_partkey AND l.l_suppkey = ps.ps_suppkey
WHERE l.l_commitdate >= '1994-10-01'
AND l.l_commitdate < '1995-01-01'
AND l.l_returnflag <> 'R'
GROUP BY p.p_mfgr
)
SELECT p_mfgr, profit
FROM manufacturer_profit
WHERE profit = (SELECT MAX(profit) FROM manufacturer_profit);

Execution Result:

p_mfgr profit
Manufacturer#2 5.4341928e+08

1 rows