Professional Documents
Culture Documents
Aiya Zeinulla Se-2008 Dbms Ass6
Aiya Zeinulla Se-2008 Dbms Ass6
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)
FROM doctor
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)
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
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