"Test case is wrong. It expects to sort in asc order of month_year.
-- Write your query here
SELECT
strftime('%Y-%m', createdat) AS monthyear,
COUNT(DISTINCT userid) AS numcustomers,
COUNT(t.id) AS num_orders,
SUM(price * quantity) AS order_amt
FROM
transactions t
INNER JOIN products p
ON t.product_id = p.id
GROUP BY
month_year
ORDER BY
month_year
;
"
Aneesha K. - "Test case is wrong. It expects to sort in asc order of month_year.
-- Write your query here
SELECT
strftime('%Y-%m', createdat) AS monthyear,
COUNT(DISTINCT userid) AS numcustomers,
COUNT(t.id) AS num_orders,
SUM(price * quantity) AS order_amt
FROM
transactions t
INNER JOIN products p
ON t.product_id = p.id
GROUP BY
month_year
ORDER BY
month_year
;
"See full answer
"WITH suspicious_transactions AS (
SELECT
c.first_name,
c.last_name,
t.receipt_number,
COUNT(t.receiptnumber) OVER (PARTITION BY c.customerid) AS noofoffences
FROM
customers c
JOIN
transactions t ON c.customerid = t.customerid
WHERE
t.receipt_number LIKE '%999%'
OR t.receipt_number LIKE '%1234%'
OR t.receipt_number LIKE '%XYZ%'
)
SELECT
first_name,
last_name,
receipt_number,
noofoffences
FROM
suspicious_transactions
WHERE
noofoffences >= 2;"
Jayveer S. - "WITH suspicious_transactions AS (
SELECT
c.first_name,
c.last_name,
t.receipt_number,
COUNT(t.receiptnumber) OVER (PARTITION BY c.customerid) AS noofoffences
FROM
customers c
JOIN
transactions t ON c.customerid = t.customerid
WHERE
t.receipt_number LIKE '%999%'
OR t.receipt_number LIKE '%1234%'
OR t.receipt_number LIKE '%XYZ%'
)
SELECT
first_name,
last_name,
receipt_number,
noofoffences
FROM
suspicious_transactions
WHERE
noofoffences >= 2;"See full answer
"SELECT
d.department_name,
SUM(o.orderamount) AS totalrevenue
FROM
orders o
JOIN
departments d ON o.departmentid = d.departmentid
WHERE
o.order_date >= DATE('now', '-12 months')
GROUP BY
d.department_name
ORDER BY
total_revenue DESC;
"
Jayveer S. - "SELECT
d.department_name,
SUM(o.orderamount) AS totalrevenue
FROM
orders o
JOIN
departments d ON o.departmentid = d.departmentid
WHERE
o.order_date >= DATE('now', '-12 months')
GROUP BY
d.department_name
ORDER BY
total_revenue DESC;
"See full answer
Coding
SQL
🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.
"select DISTINCT p.product_id,
p.product_name ,
CASE when sale_date is null then 'Not Sold'
else 'Sold'
END as sale_status
from products p
left join sales s
on p.productid= s.productid
`"
Gowtami K. - "select DISTINCT p.product_id,
p.product_name ,
CASE when sale_date is null then 'Not Sold'
else 'Sold'
END as sale_status
from products p
left join sales s
on p.productid= s.productid
`"See full answer
"SELECT DISTINCT title,
ROUND(AVG(rating) over (partition by title),1) avg_rating,
ROUND(AVG(rating) over (partition by genre),1) genre_rating
FROM rating r
JOIN movie m
ON r.movieid=m.movieid
ORDER by 1"
Harshi B. - "SELECT DISTINCT title,
ROUND(AVG(rating) over (partition by title),1) avg_rating,
ROUND(AVG(rating) over (partition by genre),1) genre_rating
FROM rating r
JOIN movie m
ON r.movieid=m.movieid
ORDER by 1"See full answer
"from typing import List
def traprainwater(height: List[int]) -> int:
if not height:
return 0
l, r = 0, len(height) - 1
leftMax, rightMax = height[l], height[r]
res = 0
while l < r:
if leftMax < rightMax:
l += 1
leftMax = max(leftMax, height[l])
res += leftMax - height[l]
else:
r -= 1
rightMax = max(rightMax, height[r])
"
Anonymous Roadrunner - "from typing import List
def traprainwater(height: List[int]) -> int:
if not height:
return 0
l, r = 0, len(height) - 1
leftMax, rightMax = height[l], height[r]
res = 0
while l < r:
if leftMax < rightMax:
l += 1
leftMax = max(leftMax, height[l])
res += leftMax - height[l]
else:
r -= 1
rightMax = max(rightMax, height[r])
"See full answer
"this task is misleading . i used lag(1) and lead(1) cuz it did not say "compare temperature from 2 days before and 1 day before" , it reads to me as if its asking "compare cur temperature to prev and future and see if it rose and fall""
Erjan G. - "this task is misleading . i used lag(1) and lead(1) cuz it did not say "compare temperature from 2 days before and 1 day before" , it reads to me as if its asking "compare cur temperature to prev and future and see if it rose and fall""See full answer
"SELECT
p1.player_name AS player1,
p2.player_name AS player2,
ABS(p1.level - p2.level) AS level_disparity
FROM
players p1
JOIN
players p2 ON p1.playername < p2.playername
WHERE
ABS(p1.level - p2.level) <= 5
ORDER BY
level_disparity ASC;"
Jayveer S. - "SELECT
p1.player_name AS player1,
p2.player_name AS player2,
ABS(p1.level - p2.level) AS level_disparity
FROM
players p1
JOIN
players p2 ON p1.playername < p2.playername
WHERE
ABS(p1.level - p2.level) <= 5
ORDER BY
level_disparity ASC;"See full answer
"with cte as
(select *,
row_number() over(order by score desc) as rn
from players)
select player_name, score, rn as ranking
from cte
where rn= 4 or rn =6 or rn =11
`"
Gowtami K. - "with cte as
(select *,
row_number() over(order by score desc) as rn
from players)
select player_name, score, rn as ranking
from cte
where rn= 4 or rn =6 or rn =11
`"See full answer