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
1 change: 1 addition & 0 deletions CombineTwoTables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Select p.firstName,p.lastName,a.city,a.state from Person p Left join Address a on a.personId=p.personId;
16 changes: 16 additions & 0 deletions CusStrictlyIncrease.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
WITH CTE AS (
SELECT
customer_id,
YEAR(order_date) AS year,
SUM(price) AS price
FROM orders
GROUP BY customer_id, year
)
SELECT c1.customer_id
FROM CTE c1
LEFT JOIN CTE c2
ON c1.customer_id = c2.customer_id
AND c1.year + 1 = c2.year
AND c1.price < c2.price
GROUP BY c1.customer_id
HAVING COUNT(c2.customer_id) = COUNT(c1.customer_id);
12 changes: 12 additions & 0 deletions GamePlayAnalysis2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Approach 1:
Select a.player_id, a.device_id as first_login from Activity a where a.event_date in (select min(b.event_date) From Activity b where a.player_id=b.player_id);


#Approach 2:
select player_id,first_value(device_id) over (partition by player_id order by event_date) as device_id from activity;



#Approach 3:
select player_id,last_value(device_id) over (partition by player_id order by event_date desc range between unbounded preceding and unbounded following) as device_id from activity;

1 change: 1 addition & 0 deletions GamePlayAnalysis3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select player_Id, event_date, sum(games_played) over (partition by player_id order by event_date) as games_played_so_far from activity;
18 changes: 18 additions & 0 deletions ShortestDis.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Approach 1:
Select round(sqrt(min(pow(p2.x-p1.x,2)+pow(p2.y-p1.y,2))),2) as ‘shortest’ from point2d p1 inner join point2d p2 on (p1.x>=p2.x and p1.y>p2.y) or (p1.x<=p2.x and p1.y>p2.y) or (p1.x<p2.x and p1.y=p2.y);



#Approach 2:
WITH RankedDistances AS (
SELECT
p1.x AS x1, p1.y AS y1, p2.x AS x2, p2.y AS y2,
SQRT(POW(p2.x - p1.x, 2) + POW(p2.y - p1.y, 2)) AS distance,
RANK() OVER (ORDER BY SQRT(POW(p2.x - p1.x, 2) + POW(p2.y - p1.y, 2))) AS rank
FROM Point2D p1
INNER JOIN Point2D p2
ON (p1.x != p2.x OR p1.y != p2.y)
)
SELECT ROUND(distance, 2) AS 'shortest'
FROM RankedDistances
WHERE rank = 1;