0% found this document useful (0 votes)
6 views

SQL Company Specific Questions

The document outlines SQL queries related to a Hospital database, including retrieving physician names trained in specific procedures, counting patients with appointments, identifying department heads, calculating employee billing based on hours worked, and finding the second maximum hours reported by employees in a specific department. Each query includes instructions on table relationships, output formats, and sample outputs. The queries require knowledge of SQL syntax and database structure to execute effectively.

Uploaded by

griffingeo7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

SQL Company Specific Questions

The document outlines SQL queries related to a Hospital database, including retrieving physician names trained in specific procedures, counting patients with appointments, identifying department heads, calculating employee billing based on hours worked, and finding the second maximum hours reported by employees in a specific department. Each query includes instructions on table relationships, output formats, and sample outputs. The queries require knowledge of SQL syntax and database structure to execute effectively.

Uploaded by

griffingeo7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SQL Company Specific ques ons

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).

Sort the output by ascending order of 'physician name'.

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.

 Refer Output format sec on for the output header names.

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

Bob Tesla Follicular Demiectomy

Christopher Turk Reverse Rhinopodoplasty

Christopher Turk Obtuse Pyloric Recombobula on

Christopher Turk Reversible Pancreomyoplasty

Elliot Reid Obfuscated Dermogastrotomy

John Dorian Obtuse Pyloric Recombobula on

John Wilson Reverse Rhinopodoplasty

John Wilson Folded Demiophtalmectomy

John Wilson Reversible Pancreomyoplasty

Keith Dudemeister Complete Walletectomy

Molly Clock Obfuscated Dermogastrotomy

Steffi Jones Follicular Demiectomy

Todd Quinlan Obtuse Pyloric Recombobula on

Todd Quinlan Obfuscated Dermogastrotomy

Todd Quinlan Reversible Pancreomyoplasty

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

2. Table names are case sensi ve.

3. Refer Output format sec on for the output header names.


Output Format

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:

1. Refer tables 'physician' and 'department' from the given ER diagram.

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)

3. Table names are case sensi ve.

4. Refer Output format sec on for the output header names.

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

General Medicine Steffi Jones

Orthopedics Bob Tesla

Psychiatry Molly Clock

Surgery John Wilson

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)

Billing column as below:

a) “Over Billed” if total hours > 40

b) “Billed as per plan” if total hours = 40

c) “Under Billed” if total hours < 40 and > 0

d) "Not Billed" if total hours = 0 (or if that par cular employee is not listed in WeeklyTimeSheet
table)

Query output columns - “Employee_Name”, “Total_Hours”, and “Billing”

Sort the output by ascending order of employee id.

Note:

 Refer the schema for table names and column names

 Table names are case sensi ve

 “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

The required input tables are populated in the back end.

Output Format

Follow the below output header for the query to be considered.


Employee_Name, Total_Hours, Billing

Sample Output

Employee_Name Total_Hours Billing

Antony 40 Billed as per plan

Peter 40 Billed as per plan

George 45 Over Billed

Michael50 Over Billed

Robert 0 Not Billed

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.

Department_Name, Employee_Name, Hours

Note:

 Refer the schema for table names and column names

 Table names are case sensi ve

 “WeeklyTimeSheet” table stores the hours spent by employee in mul ple departments for a
given week (i.e. only one week)

 Use ORDER BY concept

 Refer Output Format sec on for the header names while displaying the output.

Input Format

The required input tables are populated in the back end.

Output Format

Follow the below output header for the query to be considered.

Department_Name, Employee_Name, Hours

Output

Department_Name Employee_Name Hours

Manufacturing Antony 30

You might also like