Tables And what i need 我正在嘗試爲5個學校項目創建一個視圖。到目前爲止的聲明是這樣的:嘗試加入多個表格
CREATE view lager AS
Select produkt.produktNumber,
(SELECT buyphone.lagerNummer FROM bluecity.buyphone) AS 'Lagernummer',
produkt.produktBrand,
produkt.produktModel,
sizeMemory.memoryInformation,
(SELECT buyphone.colorValue FROM bluecity.buyphone) AS 'Farve',
(SELECT buyphone.conditionValue FROM bluecity.buyphone) AS 'Stand'
FROM bluecity.produkt
JOIN bluecity.sizememory ON bluecity.produkt.memorySize = bluecity.sizememory.memorySize
JOIN bluecity.color ON buyphone.colorValue = bluecity.color.colorInformation
JOIN bluecity.conditions ON buyphone.conditionValue = bluecity.conditions.conditionInformation
但我似乎無法得到正確的加入。主表bluecity.produkt需要將其某些值與其他表連接起來。內存大小的第一次連接起作用,但就是這樣。如果有意義的話,主表應該保存一個整數值,這個整數值可以從連接表中提取出意義。
幫助是非常appriciated,如果你能解釋爲什麼以及如何更好,所以我可以嘗試理解。
新增創建語句
CREATE DATABASE bluecity;
CREATE TABLE bluecity.Member
(memberNumber INTEGER(5) NOT NULL,
firstName VARCHAR(50) NOT NULL,
lastName VARCHAR(25) NOT NULL,
address VARCHAR(40) NOT NULL,
zipNumber INTEGER(4) NOT NULL,
phoneNumber INTEGER(8) NOT NULL,
email VARCHAR(35) NOT NULL,
statusValue INTEGER(1) NOT NULL,
FOREIGN KEY (zipNumber) REFERENCES bluecity.zipCode(zipNumber),
FOREIGN KEY (statusValue) REFERENCES bluecity.ID(statusValue),
PRIMARY KEY (memberNumber));
CREATE TABLE bluecity.ID
(statusValue INTEGER(1) NOT NULL,
information VARCHAR(19) NOT NULL,
PRIMARY KEY (statusValue))
CREATE TABLE bluecity.zipCode
(zipNumber INTEGER(4) NOT NULL,
city VARCHAR(32) NOT NULL,
PRIMARY KEY (zipNumber));
CREATE TABLE bluecity.Produkt
(produktNumber INTEGER(5) NOT NULL,
produktType VARCHAR(30) NOT NULL,
produktBrand VARCHAR(30) NOT NULL,
produktModel VARCHAR(30) NOT NULL,
memorySize INTEGER(2) NOT NULL,
FOREIGN KEY (memorySize) REFERENCES bluecity.sizeMemory(memorySize),
PRIMARY KEY (produktNumber));
CREATE TABLE bluecity.Conditions
(conditionValue INTEGER(1) NOT NULL,
conditionInformation VARCHAR(13) NOT NULL,
PRIMARY KEY (conditionValue));
CREATE TABLE bluecity.sizeMemory
(memorySize INTEGER(1) NOT NULL,
memoryInformation VARCHAR(5) NOT NULL,
PRIMARY KEY (memorySize));
CREATE TABLE bluecity.Color
(colorValue INTEGER(2) NOT NULL,
colorInformation VARCHAR(20) NOT NULL,
PRIMARY KEY (colorValue));
CREATE TABLE bluecity.Prices
(conditionValue INTEGER(1) NOT NULL,
produktNumber INTEGER(5) NOT NULL,
price INTEGER(6) NOT NULL,
FOREIGN KEY (conditionValue) REFERENCES bluecity.Conditions(conditionValue),
FOREIGN KEY (produktNumber) REFERENCES bluecity.Produkt(produktNumber),
PRIMARY KEY (conditionValue, produktNumber));
CREATE TABLE bluecity.buyPhone
(IMEI Integer(15) NOT NULL,
lagerNummer INTEGER(7) NOT NULL,
produktNumber INTEGER(5) NOT NULL,
colorValue INTEGER(2) NOT NULL,
conditionValue INTEGER(1) NOT NULL,
FOREIGN KEY (produktNumber) REFERENCES bluecity.Produkt(produktNumber),
FOREIGN KEY (colorValue) REFERENCES bluecity.Color(colorValue),
FOREIGN KEY (conditionValue) REFERENCES bluecity.Conditions(conditionValue), PRIMARY KEY (IMEI));
子查詢(大括號中的那個)返回多少個記錄? – 0xCAFEBABE
嗯,我認爲它只返回一個。 –
你使用多個數據庫嗎?否則,爲什麼kepp提到數據庫名稱。另外,你的問題還不清楚。如果您願意,可以考慮遵循以下簡單的兩步操作步驟:1.如果您尚未這樣做,請提供適當的CREATE和INSERT語句(和/或sqlfiddle),以便我們可以更輕鬆地複製問題。 2.如果您尚未這樣做,請提供與步驟1中提供的信息相對應的所需結果集。 – Strawberry