diff --git a/Average Salary Department vs Company.sql b/Average Salary Department vs Company.sql new file mode 100644 index 0000000..d5e52e8 --- /dev/null +++ b/Average Salary Department vs Company.sql @@ -0,0 +1,13 @@ +WITH companyAvg AS( + SELECT date_format(pay_date, '%Y-%m') AS 'pay_month', AVG(amount) AS 'company_avg' FROM salary GROUP BY pay_month +), +deptAvg AS( + SELECT date_format(pay_date, '%Y-%m') AS 'pay_month', department_id, AVG(amount) AS 'department_avg' FROM Salary JOIN Employee ON Salary.employee_id = employee.employee_id GROUP BY department_id, pay_month +) +SELECT deptAvg.pay_month, department_id, ( + CASE + WHEN department_avg > company_avg THEN 'higher' + WHEN department_avg < company_avg THEN 'lower' + ELSE 'same' + END +) AS 'comparison' FROM companyAvg JOIN deptAvg ON companyAvg.pay_month = deptAvg.pay_month \ No newline at end of file diff --git a/Game Play Analysis I.sql b/Game Play Analysis I.sql new file mode 100644 index 0000000..b76bfe2 --- /dev/null +++ b/Game Play Analysis I.sql @@ -0,0 +1 @@ +SELECT player_id, MIN(event_date) AS 'first_login' FROM Activity GROUP BY player_id \ No newline at end of file diff --git a/Report Contiguos Dates.sql b/Report Contiguos Dates.sql new file mode 100644 index 0000000..0e2e7c9 --- /dev/null +++ b/Report Contiguos Dates.sql @@ -0,0 +1,12 @@ +WITH CTE AS ( + SELECT fail_date AS 'dat', 'failed' AS period_state FROM Failed WHERE YEAR(fail_date) = 2019 + UNION ALL + SELECT success_date AS 'dat', 'succeeded' AS period_state FROM Succeeded WHERE YEAR(success_date) = 2019 +), +ACTE AS ( + SELECT dat, period_state, ROW_NUMBER() OVER (ORDER BY dat) AS 'rn_overall', ROW_NUMBER() OVER (PARTITION BY period_state ORDER BY dat) AS 'rn_period' FROM CTE +), +ANCTE AS ( + SELECT dat, period_state, rn_overall - rn_period AS 'group_key' FROM ACTE +) +SELECT period_state, MIN(dat) AS 'start_date', MAX(dat) AS 'end_date' FROM ANCTE GROUP BY period_state, group_key ORDER BY start_date \ No newline at end of file diff --git a/Student Report by Geography.sql b/Student Report by Geography.sql new file mode 100644 index 0000000..6c30f87 --- /dev/null +++ b/Student Report by Geography.sql @@ -0,0 +1,12 @@ +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; \ No newline at end of file