Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions AvgSalOfDeptVsCom.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
SELECT departmentSalary.pay_month, department_id,
CASE
WHEN departmentAvg > companyAvg THEN 'higher'
WHEN departmentAvg < companyAvg THEN 'lower'
ELSE 'same'
END AS 'comparison'
FROM (
SELECT date_format(pay_date, '%Y-%m') AS 'pay_month', department_id, AVG(amount) AS 'departmentAvg'
FROM Salary JOIN Employee ON Salary.employee_id = Employee.employee_id
GROUP BY department_id, pay_month
) AS departmentSalary
JOIN (
SELECT date_format(pay_date, '%Y-%m') AS 'pay_month', AVG(amount) AS 'companyAvg'
FROM Salary
GROUP BY pay_month
) AS companySalary
ON departmentSalary.pay_month = companySalary.pay_month;
2 changes: 2 additions & 0 deletions GamePlayAnalysis1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT DISTINCT player_id, MIN(event_date) OVER(PARTITION BY player_id ORDER BY event_date) AS 'first_login'
FROM activity;
14 changes: 14 additions & 0 deletions ReportContiguousDates.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
WITH CTE AS (
SELECT fail_date AS 'dat', 'failed' AS period_state, rank() OVER (ORDER BY fail_date) AS 'rnk'
FROM failed WHERE YEAR(fail_date) = 2019
UNION ALL
SELECT success_date AS 'dat', 'succeeded' AS period_state, rank() OVER (ORDER BY success_date) AS 'rnk'
FROM succeeded WHERE YEAR(success_date) = 2019
)

SELECT period_state, MIN(dat) AS start_date, MAX(dat) AS end_date
FROM (
SELECT *, (rank() OVER (ORDER BY dat) - rnk) AS 'group_rnk' FROM CTE
) AS y
GROUP BY group_rnk, period_state
ORDER BY start_date;
19 changes: 19 additions & 0 deletions StudentsReportByGeography.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
WITH first AS (
SELECT name AS 'America', ROW_NUMBER() OVER(ORDER BY name) AS 'rnk'
FROM student
WHERE continent = 'America'
),
second AS (
SELECT name AS 'Asia', ROW_NUMBER() OVER(ORDER BY name) AS 'rnk'
FROM student
WHERE continent = 'Asia'
),
third AS (
SELECT name AS 'Europe', ROW_NUMBER() OVER(ORDER BY name) AS 'rnk'
FROM student
WHERE continent = 'Europe'
)
SELECT America, Asia, Europe
FROM second
RIGHT JOIN first ON first.rnk = second.rnk
LEFT JOIN third ON first.rnk = third.rnk;