You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: consequitive.sql
+13-15
Original file line number
Diff line number
Diff line change
@@ -12,26 +12,24 @@ WITH cte AS (
12
12
LAST_VALUE(model) OVER (PARTITION BY category ORDER BY price DESC RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS least_expensive_product_name
13
13
FROM products
14
14
)
15
-
SELECT
16
-
category,
17
-
model,
18
-
price,
19
-
expensive_product_name,
20
-
least_expensive_product_name
21
-
FROM cte;
15
+
SELECT*FROM cte;
16
+
22
17
23
18
-- Query to find users who have logged in consecutively 3 or more times
24
19
25
20
SELECT DISTINCT repeated_names
26
21
FROM (
27
-
SELECT*,
28
-
-- Check if the current user_name is the same as the next two user_name values
29
-
CASE
30
-
WHEN user_name = LEAD(user_name) OVER (ORDER BY login_id)
31
-
AND user_name = LEAD(user_name, 2) OVER (ORDER BY login_id)
32
-
THEN user_name
33
-
ELSE NULL
34
-
END AS repeated_names
22
+
SELECT
23
+
*,
24
+
-- Check if the current user_name is the same as the next two user_name values
25
+
CASE
26
+
WHEN
27
+
user_name = LEAD(user_name) OVER (ORDER BY login_id) AND
28
+
user_name = LEAD(user_name, 2) OVER (ORDER BY login_id)
29
+
THEN
30
+
user_name
31
+
END AS repeated_names
32
+
35
33
FROM login_details
36
34
) AS x
37
35
-- Filter out rows where repeated_names is not null
0 commit comments