Forum Moderators: open
Im not gonna beat around the bush, i have pretty much no clue about sql statements, and need this done to pass my coursework. Any help would be GREATLY appreciated....
The relational schema shown below is part of a hospital database.
Patient (patientNo, patName, patAddr, DOB) Ward (wardNo, wardName, wardType, noOfBeds)
Contains (patientNo, wardNo, admissionDate) Drug (drugNo, drugName, costPerUnit)
Prescribed (patientNo, drugNo, unitsPerDay, startDate, finishDate)
Formulate the following SQL statements using MySQL5;
a. List all the patients’ details, alphabetically by name.
b. List all the patients contained in the ‘Surgical’ ward.
c. List all the patients admitted today.
d. Find the names of all the patients being prescribed ‘Morphine’.
e. What is the total cost of Morphine supplied to a patient called ‘John Smith’ ?
f. What is the maximum, minimum and average number of beds in a ward? Create appropriate column headings for the results table.
g. For each ward that admitted more than 10 patients today, list the ward number, ward type and number of beds in each ward.
h. List the numbers and names of all patients and the drugNo and number of units of their medication. The list should also include the details of patients that are not prescribed medication.
I realise this is a big ask, but no harm in trying..
Cheers
For a) look at select statements, b) c) d) look at inner joins, e) f) g) look at group by and aggregate functions, and h) look at outer joins.
Clever assignment as you'll know most of the statements in standard SQL once you've written the statements.
Good luck.
-Peter
w3schools (or guess the address)
This may lead to a worthless copycat domain name link farm site - I kick myself every time I accidentally go there. The URL to W3Schools is http://www.w3schools.com/ [w3schools.com]
A better resource in this case might be the mySQL documentation: http://dev.mysql.com/doc/ [dev.mysql.com]. Not so great for tutorials, but lots of examples you can learn by.
Welcome aboard, unfortunately "homework assistance" is disallowed by the TOS [webmasterworld.com].