SQL Query Documentation

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Sql Documentation

Expected output.
Query 2

Query 3
Query 4

Query - 5
Query 6

Query 7
Query 8

Query 9
Query 10

Query 11
select n,if (1=(select count(*) from bst as b where b.n = a.n
and b.p is null),'Root', if (0=(select count(*) from bst as c
where c.p = a.n),'Leaf','Inner')) from bst as a
group by n
order by n

Window Function
 Assign a unique row number to each row in the employees table, ordered by
employee_id.
SELECT * ,row_number() over(order by id ) as row_numbers from employees;

 Assign a unique row number within each department, ordered by salary.

SELECT * ,ROW_NUMBER() OVER( partition by department ORDER BY SALARY) AS


row_numbers from employees;

You might also like