-- using default substitutions

/* TPC_H  Query 4 - Order Priority Checking */

SELECT	O_ORDERPRIORITY,
	COUNT(*)		AS ORDER_COUNT
FROM	ORDERS
WHERE	O_ORDERDATE	>= '1993-07-01' AND
	O_ORDERDATE	< dateadd (mm, 3,  cast ('1993-07-01' as date)) AND
	EXISTS		(	SELECT	*
				FROM	LINEITEM
				WHERE	L_ORDERKEY	= O_ORDERKEY AND
					L_COMMITDATE	< L_RECEIPTDATE
			)
GROUP	BY	O_ORDERPRIORITY
ORDER	BY	O_ORDERPRIORITY
