Get the step-by-step solution for this question inside the Vidyadip app.
Get the answer in the appGenerate a complete, print-ready paper with questions like this in minutes — across 16+ boards, with answer keys.
Table: HOSPITAL
| PNo | Name | Age | Department | DateofAdm | Charges | Sex |
| 1 | Mayank | 65 | Surgery | 23/02/2018 | 600 | M |
| 2 | Babita | 24 | ENT | 01/01/2019 | 400 | F |
| 3 | Kashish | 45 | Orthopaedic | 19/12/2018 | 400 | M |
| 4 | Tarun | 12 | Surgery | 01/10/2018 | 600 | M |
| 5 | Manisha | 36 | ENT | 12/01/2018 | 400 | F |
| 6 | Imran | 16 | ENT | 24/02/2018 | 400 | M |
| 7 | Ankita | NULL | Cardiology | 20/08/2018 | 800 | F |
| 8 | Zoya | 45 | Gynecology | 22/02/2018 | 500 | F |
| 9 | Kush | 19 | Cardiology | 13/01/2019 | 800 | M |
| 10 | Shalini | 31 | Medicine | 19/02/2018 | 300 | F |
Note: PNo is the primary key in the above table.
Write SQL commands for the statements (a) to (g) on the table HOSPITAL.
(a) To show all the information about the patients of the cardiology department.
(b) To list the names of female patients who are either in the orthopaedic or surgery department.
(c) To list the name of all the patients with their date of admission in ascending order.
(d) To display the patient’s name, charges, the age for female patients only.
(e) To count the number of patients with age > 30.
(f) To display various departments.
(g) To display the number of patients in each department.
Write the SQL query questions from (i) to (iv) and write the output of SQL command for questions from (v) to (vii) given below:
| EMPID | FIRST NAME | LAST NAME | ADDRESS | CITY |
| 010 | George | Smith | 83 First Street | Howard |
| 105 | Mary | Jones | 842 Vine Ave. | Losantiville |
| 152 | Sam | Tones | 33 Elm St. | Paris |
| 215 | Sarah | Ackerman | 440 U.S. 110 | Upton |
| 244 | Manila | Sengupta | 24 Friends Street | New Delhi |
| 300 | Robert | Samuel | 9 Fifth Cross | Washington |
| 335 | Henry | Williams | 12 Moore Street | Boston |
| 400 | Rachel | Lee | 121 Harrison St. | New York |
| 441 | Peter | Thompson | 11 Red Road | Paris |
Table: EMPSalary
| EMPID | SALARY | BENEFITS | DESIGNATION |
| 010 | 75000 | 15000 | Manager |
| 105 | 65000 | 15000 | Manager |
| 152 | 80000 | 25000 | Director |
| 215 | 75000 | 12500 | Manager |
| 244 | 50000 | 12000 | Clerk |
| 300 | 45000 | 10000 | Clerk |
| 355 | 40000 | 10000 | Clerk |
| 4000 | 32000 | 7500 | Salesman |
| 441 | 28000 | 7500 | Salesman |
Write the SQL commands for the following :
(i) To show firstname, lastname, address and city of all employees living in paris.
(ii) To display the content of Employees table in ascending order of Firstname.
(iii) To display the firstname,lastname and total salary of all managers from the tables employee and empsalary, where total salary is calculated as
salary+benefits.
(iv) To display the maximum salary among managers and clerks from the table Empsalary.
Give the Output of following SQL commands:
(v) Select firstname, salary from employees, empsalary where designation = ‘Salesman’ and Employees.
empid=Empsalary.empid;
(vi) Select count(distinct designation) from empsalary;
(vii) Select designation, sum(salary) from empsalary group by designation having count(*) >2;
The program is to be implemented to sub plot