Here is your request:
SELECT s.sno, SUM(sp.qty) as GRTQ
FROM s, p, sp
WHERE s.sno = sp.sno AND p.pno = sp.pno AND (p.color = "red" OR p.color="green")
GROUP BY s.sno, s.sname
HAVING GRTQ > 300
ORDER BY GRTQ ASC;
The resulting output is:
+
| sno | GRTQ |
+
| s4 | 500 |
| s2 | 700 |
| s1 | 800 |
+
You can verify this by calculating it yourself.
i.e. the red or green parts are p1, p2, p4, p6
Among them:
s4 is supplied only p2 and p4, in quantities of 200 and 300, respectively. Total = 500
s2 p1 p2, 300 400 . = 700
s1 : 300 + 200 + 200 + 100. = 800