From 8e79ba3a81a699ba29cd5f58e5de494550eaaaf3 Mon Sep 17 00:00:00 2001 From: Ankitha Boindala Date: Thu, 2 Jan 2025 19:57:05 -0600 Subject: [PATCH] commit --- Game_play_analysis_i.sql | 2 ++ avg_salary.sql | 15 +++++++++++++++ report_contiguous_dates.sql | 10 ++++++++++ student_report.sql | 11 +++++++++++ 4 files changed, 38 insertions(+) create mode 100644 Game_play_analysis_i.sql create mode 100644 avg_salary.sql create mode 100644 report_contiguous_dates.sql create mode 100644 student_report.sql diff --git a/Game_play_analysis_i.sql b/Game_play_analysis_i.sql new file mode 100644 index 0000000..a93b98e --- /dev/null +++ b/Game_play_analysis_i.sql @@ -0,0 +1,2 @@ +SELECT player_id, MIN(event_date) AS 'first_login' +FROM Activity GROUP BY player_id; \ No newline at end of file diff --git a/avg_salary.sql b/avg_salary.sql new file mode 100644 index 0000000..250c53a --- /dev/null +++ b/avg_salary.sql @@ -0,0 +1,15 @@ +with temp as ( + select s.pay_date, e.department_id, + avg(s.amount) over(partition by s.pay_date order by s.pay_date) avg_company_salary, + avg(s.amount) over(partition by e.department_id, s.pay_date order by s.pay_date) avg_dept_salary + from salary s + inner join employee e + on s.employee_id = e.employee_id + ) +select date_format(pay_date,"%Y-%m") as pay_month, + department_id, + case when avg_dept_salary > avg_company_salary then 'higher' + when avg_dept_salary < avg_company_salary then 'lower' + else 'same' end as comparison +from temp +group by pay_month, department_id order by pay_date desc; \ No newline at end of file diff --git a/report_contiguous_dates.sql b/report_contiguous_dates.sql new file mode 100644 index 0000000..3ffa649 --- /dev/null +++ b/report_contiguous_dates.sql @@ -0,0 +1,10 @@ +with state_table as( + select fail_date dates, 'failed' state from Failed where year(fail_date) = 2019 + union + select *, 'succeeded' state from Succeeded where year(success_date) = 2019 +), +rank_table as( + select dates, state, dense_rank()over(partition by state order by dates,state) rnk from state_table +) +select state period_state, min(dates) start_date, min(dates)+ interval count(dates)-1 day end_date +from rank_table group by state,dates-interval rnk day order by start_date \ No newline at end of file diff --git a/student_report.sql b/student_report.sql new file mode 100644 index 0000000..229be19 --- /dev/null +++ b/student_report.sql @@ -0,0 +1,11 @@ +select America,Asia,Europe from (select name as America,row_number()over(order by name) as r1 +from student +where continent='America') am +left join (select name as Asia,row_number()over(order by name) as r1 +from student +where continent='Asia') asi on am.r1=asi.r1 +left join(select name as Europe,row_number()over(order by name) as r1 +from student +where continent='Europe') e + +on am.r1=e.r1 \ No newline at end of file