All pastes #2048102 Raw Edit

Untitled

public text v1 · immutable
#2048102 ·published 2011-04-19 06:01 UTC
rendered paste body
How many mines produce both Cobald (Co) and Nickel (Ni), and what is their overall capacity for those two metals? List both the count of those mines and the sum of their Cobald&Nickel capacity (ignoring any units).
Note: Make sure to determine solely the capacity regarding Cobald and Nickel, and that you count each mine only once.

http://rp-www.cs.usyd.edu.au/~info2120/assignments/MiningDBSchema-Advanced.pdf

SELECT m.entryno, sum(p.capacity)
FROM Mine m
JOIN Produces p ON (p.mine = m.entryno)
JOIN Commodity c ON (c.comId = p.commodity)
WHERE p.commodity IN ('Co', 'Ni')
GROUP BY m.entryno
HAVING COUNT(m.entryno) > 1;