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
21 changes: 21 additions & 0 deletions Average Salary Department vs Company.sql
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions Game Play Analysis I.sql
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions Report Contiguos Dates.sql
Original file line number Diff line number Diff line change
@@ -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


27 changes: 27 additions & 0 deletions Students Report By Geography.sql
Original file line number Diff line number Diff line change
@@ -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;