0

I'm attempting to answer this question: Create a view of all patient details (patient, ward, drugs) for all patients who are 70 years old or older, excluding ward number and number of beds.

From this schema:

    Patient (patientNo, patName, patAddr, DOB)
    Ward (wardNo, wardName, wardType, noOfBeds)
    Contains (patientNo, wardNo, admissionDate)
    Drug (drugNo, drugName, costPerUnit)
    Prescribed (patientNo, drugNo, unitsPerDay, startDate, finishDate)

The query I have written is:

    CREATE VIEW [Patients Over Seventy] AS
    SELECT p.*, c.admissionDate, r.drugNo, r.unitsPerDay, r.startDate, r.finishDate
    FROM Patient p, Contain c, Prescribed r
    WHERE p.patientNo=c.patientNo AND p.DOB <=1952-05-31;

But I keep getting the error: "Query Error: Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[Patients Over Seventy] AS SELECT p.*, c.admissionDate, r.drugNo, r.unitsPerDay,' at line 1"

What am I getting wrong here?

3
  • Not sure about the syntax containing the [] characters, but try with CREATE VIEW Patients_Over_Seventy ... instead. Commented Jun 2, 2022 at 2:24
  • @PaulT. Just gave that a go, and the same error is still coming up sadly Commented Jun 2, 2022 at 3:32
  • Try checking the SQL query itself runs without the CREATE VIEW name AS. If not try enclosing the field names with double quotes. Commented Jun 2, 2022 at 7:00

1 Answer 1

0

I see several issues.

  1. Table name in the schema Contains, in the view - Contain
  2. There is no condition to join Prescribed table to the other two tables
  3. What is DOB data type? If it's char, the comparison should be p.DOB <='1952-05-31', if it's date, you need to use SQL CONVERT function
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.