Informatics Practices
Write SQL queries based on the table given below:
Table: HOSPITAL
| S NO | Name | Age | Department | Datofadm | Charges | Sex |
|---|---|---|---|---|---|---|
| 1 | Arpit | 62 | Surgery | 1998-01-21 | 300 | M |
| 2 | Zareena | 22 | ENT | 1997-12-12 | 250 | F |
| 3 | Kareem | 32 | Orthopaedic | 1998-02-19 | 200 | M |
| 4 | Arun | 12 | Surgery | 1998-01-11 | 300 | M |
| 5 | Zubin | 30 | ENT | 1998-01-12 | 250 | M |
| 6 | Ketaki | 16 | ENT | 1998-02-24 | 250 | F |
| 7 | Ankita | 29 | Cardiology | 1998-02-20 | 800 | F |
| 8 | Zareen | 45 | Gynaecology | 1998-02-22 | 300 | F |
| 9 | Kush | 19 | Cardiology | 1998-01-13 | 800 | M |
| 10 | Shilpa | 23 | Nuclear Medicine | 1998-02-21 | 400 | F |
(i) To list the names of all the patients admitted after 15/01/98.
(ii) To list the names of female patients who are in ENT department.
(iii) To list names of all patients with their date of admission.
(iv) To display Patient’s Name, Charges, Age for only female patients.
Answer
(i)
SELECT NAME
FROM HOSPITAL
WHERE DATEOFADM > '1998-01-15';
Output
+--------+
| NAME |
+--------+
| Arpit |
| Kareem |
| Ketaki |
| Ankit |
| Zareen |
| Shilpa |
+--------+
(ii)
SELECT NAME
FROM HOSPITAL
WHERE SEX = 'F' AND DEPARTMENT = 'ENT';
Output
+---------+
| NAME |
+---------+
| Zareena |
| Ketaki |
+---------+
(iii)
SELECT NAME, DATEOFADM FROM HOSPITAL;
Output
+---------+------------+
| NAME | DATEOFADM |
+---------+------------+
| Arpit | 1998-01-21 |
| Zareena | 1997-12-12 |
| Kareem | 1998-02-19 |
| Arun | 1998-01-11 |
| Zubin | 1998-01-12 |
| Ketaki | 1998-02-24 |
| Ankit | 1998-02-20 |
| Zareen | 1998-02-22 |
| Kush | 1998-01-13 |
| Shilpa | 1998-02-21 |
+---------+------------+
(iv)
SELECT NAME, CHARGES, AGE
FROM HOSPITAL
WHERE SEX = 'F';
Output
+---------+---------+-----+
| NAME | CHARGES | AGE |
+---------+---------+-----+
| Zareena | 250 | 22 |
| Ketaki | 250 | 16 |
| Ankit | 800 | 29 |
| Zareen | 300 | 45 |
| Shilpa | 400 | 23 |
+---------+---------+-----+
Related Questions
What is the difference between Candidate key and Alternate key?
What is the degree and cardinality of a table having 10 rows and 5 columns?
For the given table, do as directed:
Table: STUDENT
ColumnName Data type size Constraint ROLLNO Integer 4 Primary Key SNAME Varchar 25 Not Null GENDER Char 1 Not Null DOB Date Not Null FEES Integer 4 Not Null HOBBY Varchar 15 Null (i) Write SQL query to create the table.
(ii) Write SQL query to increase the size of SNAME to hold 30 characters.
(iii) Write SQL query to remove the column HOBBY.
(iv) Write SQL query to insert a row in the table with any values of your choice that can be accommodated there.
Write SQL queries based on the following tables:
Table: PRODUCT
P_ID ProductName Manufacturer Price Discount TP01 Talcum Powder LAK 40 Null FW05 Face Wash ABC 45 5 BS01 Bath Soap ABC 55 Null SH06 Shampoo XYZ 120 10 FW12 Face Wash XYZ 95 Null Table: CLIENT
C_ID ClientName City P_ID 01 Cosmetic Shop Delhi TP01 02 Total Health Mumbai FW0S 03 Live Life Delhi BS01 04 Pretty Woman Delhi SH06 05 Dreams Delhi FW12 (i) Write SQL query to display ProductName and Price for all products whose Price is in the range 50 to 150.
(ii) Write SQL Query to display details of products whose manufacturer is either XYZ or ABC.
(iii) Write SQL query to display ProductName, Manufacturer and Price for all products that are not given any discount.
(iv) Write SQL query to display ProductName and price for all products.
(v) Which column is used as Foreign Key and name the table where it has been used as Foreign key?