クエリで 2 つのテーブルを等結合しようとすると、エラー コード 1052 フィールド リストの列 FireStationHome があいまいです
これは私が以下で使用しているコードです:
SELECT FiremanID, FiremanHomeStation,StationPhone
FROM FIRE_REPORT AS F, FIRE_STATION AS FS
WHERE F.FiremanHomeStation = FS.FiremanHomeStation
AND StationPhone ='703';
フォーラムを読んで、最初のリレーションをリンク キーでリンクする必要があることを理解しています。FiremanHomeStation は、次の手順を実行するために必要な唯一のリンク キーです。
番号が '703' で始まるすべての消防士の FiremanID、FiremanHomeStation、およびステーションの電話番号を表示します。
ボイス コッド メソッドを使用して、以下を正規化しました
FIRE_REPORT(FireID,Alarms,Address,FiremanID,FiremanName,FiremanPhone,FiremanHomeStation,StationAddress,StationPhone,TruckID,LicensePlate)
ルール:
各消防士に複数の消防士を割り当てることができます 各消防士
に複数の消防車を割り当てる
ことができます 各消防士を複数の火災に割り当てることができます
各消防車と複数の火災に割り当てることができます
各消防士には 1 つのホーム ステーション
があります 各ステーションは一意です
各ステーションには単一の電話番号
主キー
FireID, FiremanID, FiremanHomeStation,TruckID
FireID -> Alarms, Address
FiremanID -> FiremanName, FiremanPhone, FiremanHomeStation
FiremanHomeStation -> StationAddress, StationPhone
TruckID -> LicensePlate
FIRE_REPORT( FireID, FiremanID, FiremanHomeStation, TruckID )
FIRE( FireID , Alarms, Address)
FIREMAN_ID( FiremanID , FiremanName, FiremanPhone)
FIRE_STATION( FiremanHomeStation , StationAddress, StationPhone)
TRUCK( TruckID , LicensePlate)
参照整合性制約
FIRE_REPORT の FireID は FIRE の
FireID に存在する必要があります FIRE_REPORT の FiremanID は FIREMAN_ID の
FiremanID に存在する必要があります FIRE_REPORT の FiremanHomeStation は FIRE_STATION の FiremanHomeStation に
存在する必要があります
create schema project_george;<br>
use project_george;<br>
CREATE TABLE FIRE (<br>
FireID int(3) NOT NULL,<br>
Alarms int(1) NOT NULL,<br>
Address varChar(25) NOT NULL,<br>
CONSTRAINT FIRE_PK PRIMARY KEY(FireID),<br>
CONSTRAINT FIRE_FR_FK FOREIGN KEY(FireID)<br>
REFERENCES FIRE_REPORT(FireID)<br>
ON UPDATE CASCADE<br>
);<br>
CREATE TABLE FIREMAN_ID (<br>
FiremanID int(3) NOT NULL,<br>
FiremanName varchar(25) NOT NULL,<br>
FiremanPhone char(10) NOT NULL UNIQUE,<br>
CONSTRAINT FI_PK PRIMARY KEY(FiremanID),<br>
CONSTRAINT FI_FR_FK FOREIGN KEY(FiremanID)<br>
REFERENCES FIRE_REPORT(FiremanID)<br>
ON UPDATE CASCADE<br>
);<br>
CREATE TABLE FIRE_STATION (<br>
FiremanHomeStation varChar(25) NOT NULL UNIQUE,<br>
StationAddress varChar(25) NOT NULL,<br>
StationPhone char(10) NOT NULL,<br>
CONSTRAINT FS_PK PRIMARY KEY(FiremanHomeStation),<br>
CONSTRAINT FS_FR_FK FOREIGN KEY(FiremanHomeStation)<br>
REFERENCES FIRE_REPORT(FiremanHomeStation)<br>
ON UPDATE CASCADE<br>
);<br>
CREATE TABLE TRUCK (<br>
TruckID int(3) NOT NULL,<br>
LicensePlate char(5) NOT NULL UNIQUE,<br>
CONSTRAINT TRUCK_PK PRIMARY KEY(TruckID),<br>
CONSTRAINT TRUCK_RC_FK FOREIGN KEY(TruckID)<br>
REFERENCES FIRE_REPORT(TruckID)<br>
ON UPDATE CASCADE<br>
);<br>
CREATE TABLE FIRE_REPORT (<br>
FireID int(3) NOT NULL,<br>
FiremanID int(3) NOT NULL,<br>
FiremanHomeStation varChar(25) NOT NULL,<br>
TruckID int(3) NOT NULL,<br>
CONSTRAINT FR_PK PRIMARY KEY(FireID,FiremanID,FiremanHomeStation,TruckID),<br>
CONSTRAINT FR_F_FK FOREIGN KEY (FireID)<br>
REFERENCES FIRE(FireID) <br>
ON UPDATE CASCADE,<br>
CONSTRAINT FR_FID_FK FOREIGN KEY(FiremanID)<br>
REFERENCES FIREMAN_ID(FiremanID)<br>
ON UPDATE CASCADE,<br>
CONSTRAINT FR_FS_FK FOREIGN KEY(FiremanHomeStation)<br>
REFERENCES FIRE_STATION(FiremanHomeStation)<br>
ON UPDATE CASCADE,<br>
CONSTRAINT FR_TRUCK_FK FOREIGN KEY(TruckID)<br>
REFERENCES TRUCK(TruckID)<br>
ON UPDATE CASCADE<br>
);<br><br>
INSERT INTO FIRE VALUES(100, 1, '4025 Medford dr, Annandale VA 22003');<br>
INSERT INTO FIRE VALUES(101, 2, '7031 Little River Turnpike Suite 5A
Annandale, VA 22003-5958');<br>
INSERT INTO FIRE VALUES(102, 3, '7001 Little River Turnpike, Annandale, VA 22003 ');<br>
INSERT INTO FIRE VALUES(103, 4, '8333 Little River Turnpike Annandale, VA 22003');<br>
INSERT INTO FIRE VALUES(104, 5, '1600 Pennsylvania Ave NW Washington, DC 20500');<br><br>
INSERT INTO FIREMAN_ID VALUES(100, 'Guliza Ormuzokova', '703-221-9918');<br>
INSERT INTO FIREMAN_ID VALUES(101, 'Lex Steele', '703-911-4450');<br>
INSERT INTO FIREMAN_ID(FiremanID,FiremanName,FiremanPhone) VALUES(102, 'George Putnam', '703-222-9918');<br>
INSERT INTO FIREMAN_ID VALUES(103, 'Steven Drasner', '571-939-1234');<br>
INSERT INTO FIREMAN_ID VALUES(104, 'Judy Miller', '571-999-1234');<br>
INSERT INTO FIREMAN_ID VALUES(105, 'Lily Thai', '703-911-4451');<br><br>
INSERT INTO FIRE_STATION VALUES('Station 29', '571 Broad st
Fairfax VA 22030', '703-200-9918');<br>
INSERT INTO FIRE_STATION VALUES('Station 229', '8914 Little River Turnpike, Fairfax, VA 22031 ', '703-900-4450');<br>
INSERT INTO FIRE_STATION VALUES('Station 429', '3988 University Dr, Fairfax, VA 22030 ', '571-900-1234');<br><br>
INSERT INTO TRUCK VALUES(1, 'burn29');<br>
INSERT INTO TRUCK VALUES(2, 'burn19');<br>
INSERT INTO TRUCK VALUES(3, 'burn09');<br><br>
/************I can't figure this on out!!!*** *****/<br>
SELECT FiremanID, FiremanHomeStation,StationPhone<br>
FROM FIRE_REPORT AS F, FIRE_STATION AS FS<br>
WHERE F.FiremanHomeStation = FS.FiremanHomeStation<br>
AND StationPhone ='703';<br>