-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries.sql
More file actions
41 lines (37 loc) · 910 Bytes
/
Copy pathqueries.sql
File metadata and controls
41 lines (37 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- Total sales per customer
SELECT customer_id,
SUM(quantity * price) AS total_sales
FROM orders
GROUP BY customer_id;
-- Customers with more than one order
SELECT customer_id,
COUNT(order_id) AS order_count
FROM orders
GROUP BY customer_id
HAVING COUNT(order_id) > 1;
-- Candidates with all required skills
SELECT candidate_id
FROM candidates
WHERE skill IN ('Python', 'Tableau', 'PostgreSQL')
GROUP BY candidate_id
HAVING COUNT(DISTINCT skill) = 3;
-- Employees earning more than company average
SELECT *
FROM employees
WHERE salary > (
SELECT AVG(salary)
FROM employees
);
-- Top 2 highest paid employees per department
SELECT name, salary, department
FROM (
SELECT name,
salary,
department,
ROW_NUMBER() OVER (
PARTITION BY department
ORDER BY salary DESC
) AS rn
FROM employees
) t
WHERE rn <= 2;