SQL Company Specific Questions
SQL Company Specific Questions
1. Given the ER diagram of Hospital database, write a query to obtain the name of the physicians
who are trained for a special treatment (procedure).
Note:
Refer the descrip on of tables given below to use in the query. Check the foreign key
rela onships from the ER diagram to join the tables. (Example: column 'physician' in
trained_in table is related to 'employeeid' in physician table. Column 'treatment' in
trained_in table is related to 'code' in procedure_data table)
'physician' - contains informa on about doctors (employee_id, name, posi on, ssn)
'procedure_data' - contains code of the procedure, procedure name (treatment name), cost of the
procedure
'trained_in' - contains details about physicians who trained in par cular procedure along with
cer fica on date and cer fica on expiry
Table names are case sensi ve.
Output Format
The output should have the below header for the query to be considered.
physician_name, treatment name
Sample Output
physician_name treatment_name
2. Given the ER diagram of Hospital database, write a query to count the number of pa ents who
booked an appointment with at least one physician.
Note:
1. 'appointment' table has all the data related to appointment booking. Pa ent details will be
present in the 'pa ent' table
The output should have the below header for the query to be considered.
number_of_pa ents
Sample Output
number_of_pa ents
11
3. Given the ER diagram of Hospital database, write a query to obtain the name of the
physicians who are the head of the department.Sort the output by ascending order of
department name.
Note:
2. Check the foreign key rela onships from the ER diagram to join the tables. (Example: column
'employeeid' in physician table is related to 'head' in department table)
Output Format
The output should have the below header for the query to be considered.
department_name, physician_name
Sample Output
department_name physician_name
4. From the Schema given below, write a query to list all the employee names, Total hours &
Billing as shown below:Total Hours: Total Timespent of that par cular employee. (If
par cular employee is not listed in WeeklyTimeSheet table, then consider total hours as 0)
d) "Not Billed" if total hours = 0 (or if that par cular employee is not listed in WeeklyTimeSheet
table)
Note:
“WeeklyTimeSheet” table stores the hours spent by employee in mul ple departments for a
given week (i.e. only one week)
Refer Output Format sec on for the header names while displaying the output.
Input Format
Output Format
Sample Output
5. From the Schema given below, write a query to find the 2nd max hour reported by employee
for the department with dep_id = 1.
Note:
“WeeklyTimeSheet” table stores the hours spent by employee in mul ple departments for a
given week (i.e. only one week)
Refer Output Format sec on for the header names while displaying the output.
Input Format
Output Format
Output
Manufacturing Antony 30