Yurttas/PL/DBL/postgres/F/01/SPJ/q07.sql

 1/*
 2REM
 3REM q07.sql
 4REM
 5REM Get project numbers for projects supplied with part 'P01'
 6REM in an average quantity greater than the greatest quantity
 7REM in which any part is supplied to project 'J01'.
 8REM
 9*/
10
11SELECT current_schema();
12SET search_path to "spj";
13
14SELECT DISTINCT jn
15FROM Shipments
16WHERE pn = 'P1'
17GROUP BY jn
18HAVING AVG(quantity) > (SELECT MAX(quantity)
19                        FROM Shipments
20                        WHERE jn='J01');