CREATE TABLE TRAIN ( TrainNumber INT NOT NULL, TrainName VARCHAR(30) NOT NULL,…
- User
CREATE TABLE TRAIN ( TrainNumber INT NOT NULL, TrainName VARCHAR(30) NOT NULL, PremiumFare INT NOT NULL, GeneralFare INT NOT NULL, SourceStation VARCHAR(30) NOT NULL, DestinationStation VARCHAR(30) NOT NULL, PRIMARY KEY (TrainNumber), UNIQUE (TrainName) );
CREATE TABLE BOOKED ( SSN CHAR(9) NOT NULL, Train_Number INT NOT NULL, VARCHAR(10) NOT NULL, Ticket_Status VARCHAR(15) NOT NULL,
PRIMARY KEY (SSN), FOREIGN KEY (Train_Number) REFERENCES TRAIN (TrainName)
);
CREATE TABLE PASSENGER ( FName VARCHAR(15) NOT NULL, LName VARCHAR(15) NOT NULL, Pass_Address VARCHAR(45) NOT NULL, City VARCHAR(15) NOT NULL, County VARCHAR(15) NOT NULL, PhoneNumber CHAR(10) NOT NULL, SSN CHAR(9) NOT NULL, BDate DATE NOT NULL,
PRIMARY KEY (SSN), FOREIGN KEY (SSN) REFERENCES BOOKED(SSN)
);
I am having a lot of trouble trying to get age from the date of birth on record. I need to make a query to get train and passenger information from passengers that are between the ages of 50 and 60 but I can't seem to get it to work.
I am thinking I probably have to do a nested query and this is what I have so far but it is not pulling any records? Yes I know I only put 50 but once I figure it out I'll add the 60 to it.
SELECT FName, LName, Pass_Address, , , Ticket_Status, TrainNumber, TrainName, SourceStation, DestinationStation FROM PASSENGER AS P, BOOKED AS B, TRAIN WHERE P.SSN=B.SSN AND B.Train_Number=TrainNumber AND P.BDate IN (
codeSELECT BDate FROM PASSENGER WHERE strftime('%Y', 'now') - strftime('%Y', BDate) >= 50 ); - Assistant
There are a couple of issues to address in your query:
In yourBOOKEDtable's foreign key definition, you have referencedTrainNamecolumn of theTRAINtable instead ofTrainNumber. It should be:
In yourBOOKEDtable's foreign key definition, you have referencedTrainNamecolumn of theTRAINtable instead ofTrainNumber. It should be:
────────────────────────────────────────────────────────────────────