CREATE TABLE Masina(
idMasina INT PRIMARY KEY NOT NULL,
marca VARCHAR(20),
model VARCHAR(20),
pretFaraDotari DOUBLE
);
CREATE TABLE Dotari(
idDotare INT PRIMARY KEY NOT NULL,
dotare VARCHAR(30),
pret INT
);
CREATE TABLE Comenzi(
idComanda INT PRIMARY KEY NOT NULL,
idMasina INT,
pretTotal DOUBLE,
discount VARCHAR(10),
FOREIGN KEY (idMasina)
REFERENCES Masina(idMasina) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE Com_Dot(
idComanda INT,
idDotare INT,
FOREIGN KEY (idComanda)
REFERENCES Comenzi(idComanda) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (idDotare)
REFERENCES Dotari(idDotare) ON DELETE CASCADE ON UPDATE CASCADE
);
我如何展示" marca"," model"," pretFaraDotari"来自" Masina"表," dotare"的总价来自" Dotari" table," pretFaraDotari" + dotare的总价格," pretTotal"来自" Comenzi"表中所有条目的表格" Comenzi"?
我需要使用一个命令显示所有这些......这是一个大问题
答案 0 :(得分:0)
我不知道我是否“完全”得到它(我不会说罗马尼亚语)但也许你正在寻找像
这样的东西select
cd.*,
c.*,
d.*,
m.*
from Com_Dot as cd,
join Comenzi as c on c.idComanda = cd.idComanda
join Dotari as d on d.idDotare = cd.idDotare
join Masina as m on m.idMasina = c.idMasina
如果您需要某种聚合,可以根据需要添加where / group。