DROP TABLE IF EXISTS employees
  
CREATE TABLE employees (
    id SERIAL PRIMARY KEY,
    name VARCHAR(50),
    department VARCHAR(50),
    salary DECIMAL(10, 2)
)
  

INSERT INTO employees (name, department, salary) VALUES
('Alice', 'Engineering', 70000),
('Bob', 'Engineering', 60000),
('Charlie', 'HR', 50000),
('David', 'HR', 55000),
('Eve', 'Marketing', 60000)
      

select sum(salary) over() = 295000 from employees limit 1
      

select avg(salary) over(partition by department) = 65000 
from employees where department = 'Engineering' limit 1
      

select row_number() over(partition by department order by name) = 2 
from employees where name = 'David' limit 1
      

select rank() over(partition by department order by salary desc) = 1 
from employees where name = 'Eve' limit 1
      

select first_value(salary) over(partition by department order by salary desc) = 70000 
from employees where department = 'Engineering' limit 1
      

select percent_rank() over(partition by department order by salary) = 0 
from employees where name = 'Charlie' limit 1
      

select ntile(4) over(partition by department order by salary) = 2 
from employees where name = 'Bob' limit 1
      

select cume_dist() over(partition by department order by salary) = 1 
from employees where name = 'Alice' limit 1
      

select last_value(salary) over(partition by department order by salary range between unbounded preceding and unbounded following) = 50000 
from employees where department = 'HR' limit 1
      

select sum(salary) over(partition by department) = 105000 
from employees where department = 'HR' limit 1