0% found this document useful (0 votes)
111 views10 pages

Aiya Zeinulla Se-2008 Dbms Ass6

The document contains 13 SQL queries to retrieve information from doctor and hospital databases. The queries use aggregation functions, subqueries, joins, and window functions. They find average salaries, minimum salaries, top salaries by hospital, rankings and row numbers of doctors by salary within each hospital.

Uploaded by

Aiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views10 pages

Aiya Zeinulla Se-2008 Dbms Ass6

The document contains 13 SQL queries to retrieve information from doctor and hospital databases. The queries use aggregation functions, subqueries, joins, and window functions. They find average salaries, minimum salaries, top salaries by hospital, rankings and row numbers of doctors by salary within each hospital.

Uploaded by

Aiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Assignment 6

1. Write a query to get the average bill_price for all bill_id above 970. (5 points)
SELECT AVG(bill_price) FROM bill
WHERE bill_id > 970

2. Write a query to calculate the average salary of male doctors whose Doctor id
less than 35. (5 points)
SELECT AVG(dc_salary) FROM doctor
WHERE dc_gender = 'Male' AND doctor_id < 35

3. Write a query to find the first name, last name of doctors and salaries of the
doctors who have a higher salary than the doctor whose last name is
‘Wyldish’. (5 points)

SELECT dc_f_name,dc_l_name,dc_salary FROM doctor

WHERE dc_salary > (SELECT dc_salary

FROM doctor

WHERE dc_l_name = 'Wyldish')


4. Write a SQL subquery to find the first name and last name of all doctors who
works as Neurologist. (5 points)
SELECT dc_f_name, dc_l_name, spzltn_name FROM doctor dc
INNER JOIN specialization sp ON sp.specialization_id = dc.splztn_id
WHERE splztn_id IN (SELECT specialization_id
FROM specialization
WHERE spzltn_name = 'Neurologist')
5. Write a SQL subquery to find the first name, last name and salary, which is
greater than the average salary of the doctors. (5 points)
SELECT dc_f_name,dc_l_name,dc_salary FROM doctor
WHERE dc_salary > (SELECT AVG(dc_salary)
FROM doctor)
6. Write a SQL subquery to find the first name of doctors, last name of doctors
and salary of doctors, which is equal to the minimum salary for this
specialization, he/she is working on. (5 points)

SELECT dc_f_name,dc_l_name,dc_salary, spzltn_name FROM doctor dc

INNER JOIN specialization sp ON sp.specialization_id = dc.splztn_id

WHERE dc_salary IN (SELECT MIN(dc_salary)

FROM doctor

GROUP BY splztn_id)

7. Write a SQL subquery to find all the information of the doctors who draws the
same salary as the minimum salary for all specializations. (10 points)

SELECT * FROM doctor

WHERE dc_salary IN (SELECT MIN(dc_salary)

FROM doctor)
8. Write a query to get three minimum salaries of doctors. (10 points)
SELECT dc_f_name,dc_l_name,dc_salary FROM doctor dc1
WHERE 3 >= (SELECT COUNT(dc_salary)
FROM doctor dc2
WHERE dc2.dc_salary <= dc1.dc_salary
ORDER BY dc1.dc_salary DESC)

9. Write a query that returns the first name, salary, gender of doctors, along with
the average salaries of each gender. Use the window function. (10 points)
SELECT dc_f_name,dc_salary,dc_gender,
AVG(dc_salary) OVER (
PARTITION BY dc_gender
)
FROM doctor
10. Write a query that filters and finds only the top paid doctor in each hospital
id. Use the window function. (10 points)
SELECT * FROM(
SELECT dc_f_name,dc_l_name,dc_salary,hospital_id,
rank() OVER (
PARTITION BY hospital_id
ORDER BY dc_salary DESC
)
FROM doctor)sub_query
WHERE rank = 1;
11.Write a SQL query using ROW_NUMBER window function. (10 points)

SELECT dc_f_name,dc_l_name,dc_salary,

ROW_NUMBER () OVER (

PARTITION BY hospital_id

ORDER BY dc_salary

FROM doctor
12.Write a SQL query using DENSE_RANK window function. (10 points)

SELECT dc_f_name,dc_l_name,dc_salary,hospital_id,

DENSE_RANK() OVER (

PARTITION BY hospital_id

ORDER BY dc_salary DESC

FROM doctor
13.Write a SQL query using FIRST_VALUE window function. (10 points)

SELECT dc_f_name,dc_l_name,dc_salary,hospital_id,

FIRST_VALUE(dc_salary) OVER (

PARTITION BY hospital_id

ORDER BY dc_salary

) AS lowest_salary_per_hospital

FROM doctor

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy