I'm building a system where I have to find the combined price of a computer system by using the database data. The first screenshot is a build from the system table.
Systems Table
Parts Table
The different kinds are: motherboard, case, ram, cpu, graphic. What I need is some way of turning the columns into rows and thereby summing the prices of each system.
Here is the table and content.
CREATE TABLE Component (
nome VARCHAR(30),
kind VARCHAR(10), /*cpu, ram, mainboard, cases*/
price INT,
PRIMARY KEY(nome)
);
CREATE TABLE Computer_system (
nome VARCHAR(30),
ram VARCHAR(20),
cpu VARCHAR(20),
mainboard VARCHAR(20),
cases VARCHAR(20),
gfx VARCHAR(20),
PRIMARY KEY(nome)
);
INSERT INTO Computer_system VALUES('SERVER1','D31','XEON1','LGA2011_D3_E_OGFX','CASE_A',null);
INSERT INTO Computer_system VALUES('SERVER2','D43','XEON3','LGA2011_D4_E_OGFX','CASE_A',null);
INSERT INTO Computer_system VALUES('CONSUMER1','D43','I71','LGA1150_D4_ATX_OGFX','CASE_B',null);
INSERT INTO Computer_system VALUES('GAMING1', 'D51', 'FX','AM3+_D5_ATX','BLACK_PEARL', 'NVIDIA_TITAN_BLACK_X');
INSERT INTO Computer_system VALUES('BUDGETO', 'D31', 'XEON1','LGA2011_D3_ATX','CASE_B', null);