From 03f642561e8a531f2b328c361008ef5f67d8fdc1 Mon Sep 17 00:00:00 2001 From: SAI NIHITH IMMANENI Date: Thu, 2 Jan 2025 23:47:29 -0600 Subject: [PATCH] PR5 Done --- Average Salary Department vs Company.sql | 21 ++++++++++++++++++ Game Play Analysis I.sql | 4 ++++ Report Contiguos Dates.sql | 21 ++++++++++++++++++ Students Report By Geography.sql | 27 ++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 Average Salary Department vs Company.sql create mode 100644 Game Play Analysis I.sql create mode 100644 Report Contiguos Dates.sql create mode 100644 Students Report By Geography.sql diff --git a/Average Salary Department vs Company.sql b/Average Salary Department vs Company.sql new file mode 100644 index 0000000..2abc5c1 --- /dev/null +++ b/Average Salary Department vs Company.sql @@ -0,0 +1,21 @@ +# Write your MySQL query statement below +WITH CTE AS( + SELECT s.id,s.employee_id,s.amount,s.pay_date,e.department_id, AVG(s.amount) OVER(PARTITION BY s.pay_date) AS 'company_avg', AVG(s.amount) OVER(PARTITION BY s.pay_date, e.department_id) AS 'dept_avg' + FROM salary s LEFT JOIN + Employee e + ON s.employee_id = e.employee_id + ORDER BY s.id +) +-- SELECT * FROM CTE + +SELECT DATE_FORMAT(pay_date, '%Y-%m')AS pay_month,department_id, +CASE + + WHEN dept_avg > company_avg THEN 'higher' + WHEN dept_avg < company_avg THEN 'lower' + ELSE 'same' +END + AS comparison + FROM CTE + GROUP BY department_id,pay_month + ORDER BY department_id \ 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..b8cbcbf --- /dev/null +++ b/Game Play Analysis I.sql @@ -0,0 +1,4 @@ +WITH CTE AS (SELECT player_id,event_date, MIN(event_date) OVER (PARTITION BY player_id) AS 'first_login' from +Activity) + +SELECT DISTINCT player_id, first_login FROM CTE \ No newline at end of file diff --git a/Report Contiguos Dates.sql b/Report Contiguos Dates.sql new file mode 100644 index 0000000..e19e780 --- /dev/null +++ b/Report Contiguos Dates.sql @@ -0,0 +1,21 @@ + +WITH CTE AS(SELECT f.fail_date AS 'Date','failed' AS status, RANK() OVER (ORDER BY f.fail_date) AS 'rnk' FROM Failed f +WHERE YEAR(f.fail_date) = 2019 +UNION +SELECT s.success_date AS 'Date','succeeded' AS status, RANK() OVER (ORDER BY s.success_date) AS 'rnk' FROM Succeeded s +WHERE YEAR(s.success_date) = 2019 +), +-- SELECT * FROM CTE ORDER BY Date + + +CTE2 AS ( +SELECT *, ROW_NUMBER() OVER(ORDER BY c.Date ) AS 'row_id'FROM CTE c +ORDER BY c.Date +) + +SELECT status AS 'period_state', MIN(Date) AS start_date, MAX(Date) AS end_date +FROM CTE2 +GROUP BY status, (row_id - rnk) +ORDER BY start_date + + diff --git a/Students Report By Geography.sql b/Students Report By Geography.sql new file mode 100644 index 0000000..2f00fa0 --- /dev/null +++ b/Students Report By Geography.sql @@ -0,0 +1,27 @@ +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 + f.America, + s.Asia, + t.Europe +FROM + first f +LEFT JOIN second s ON f.rnk = s.rnk +LEFT JOIN third t ON f.rnk = t.rnk +ORDER BY f.rnk;