-- $Id: q14-tpch04.sql 2657 2007-06-12 16:08:15Z rdempsey $
-- 14th query in 100 GB stream0 (tpch04).
SELECT 
	O_ORDERPRIORITY,
	COUNT(*) AS ORDER_COUNT
FROM 
	ORDERS
WHERE 
	O_ORDERDATE >= date '1993-05-01' AND
	O_ORDERDATE < date '1993-05-01' + interval '3' month
	AND EXISTS ( 
	SELECT 
		*
	FROM 
		LINEITEM
	WHERE 
		L_ORDERKEY = O_ORDERKEY AND
		L_COMMITDATE < L_RECEIPTDATE
				)
GROUP BY 
	O_ORDERPRIORITY
ORDER BY 
	O_ORDERPRIORITY;

