-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQuery8.sql
More file actions
21 lines (21 loc) · 833 Bytes
/
Query8.sql
File metadata and controls
21 lines (21 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Show list with all builds that include ALL of the following products:
# 1) AMD Ryzen 5 (pid 0004200), 2) AM4 Asrock motherboard (pid 0001600)
# 3) and Corsair 16GB 3200Mhz (pid 0006510).
DROP TABLE A, B, C, D;
CREATE TEMPORARY TABLE A
SELECT `buildID` AS `bid1`, `productID` AS `pid1`, `quantity` AS `q1`
FROM `buildconsistsofproduct`
WHERE `productID` = '0004200';
CREATE TEMPORARY TABLE B
SELECT `buildID` AS `bid2`, `productID` AS `pid2`, `quantity` AS `q2`
FROM `buildconsistsofproduct`
WHERE `productID` = '0001600';
CREATE TEMPORARY TABLE C
SELECT `buildID` AS `bid3`, `productID` AS `pid3`, `quantity` AS `q3`
FROM `buildconsistsofproduct`
WHERE `productID` = '0006510';
CREATE TEMPORARY TABLE D
SELECT * FROM `A`
WHERE `bid1` IN (SELECT `bid2` FROM `B`);
SELECT DISTINCT * FROM D
WHERE `bid1` IN (SELECT `bid3` FROM `C`);