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

From ZCubes Wiki
Jump to navigation Jump to search
 1/*
 2REM
 3REM q03.sql
 4REM
 5REM Get supplier numbers for suppliers supplying some project
 6REM with part 'P02' in a quantity greater than the
 7REM average shipment quantity of part 'P02' for that project.
 8REM
 9*/
10
11SELECT current_schema();
12SET search_path to "spj";
13
14SELECT DISTINCT S.sn
15FROM Shipments S
16WHERE pn = 'P2'
17  AND quantity > (SELECT AVG(T.quantity)
18                  FROM Shipments T
19                  WHERE pn = 'P2'
20                    AND S.jn = T.jn);