"Schema is wrong - id from product is mapped to id from transactions, id from product should point to product_id in transcations table"
Arshad P. - "Schema is wrong - id from product is mapped to id from transactions, id from product should point to product_id in transcations table"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 upsellcampaignid, COUNT(DISTINCT trans.userid) AS eligibleusers
FROM campaign
JOIN "transaction" AS trans
ON transactiondate BETWEEN datestart AND date_end
JOIN user
ON trans.userid = user.userid
WHERE iseligibleforupsellcampaign = 1
GROUP BY upsellcampaignid
`"
Alina G. - "SELECT upsellcampaignid, COUNT(DISTINCT trans.userid) AS eligibleusers
FROM campaign
JOIN "transaction" AS trans
ON transactiondate BETWEEN datestart AND date_end
JOIN user
ON trans.userid = user.userid
WHERE iseligibleforupsellcampaign = 1
GROUP BY upsellcampaignid
`"See full answer
"SELECT d.departmentname,SUM(o.orderamount) AS total_revenue FROM orders o
JOIN departments d
ON
d.departmentid =o.departmentid
WHERE o.orderdate >= CURRENTDATE - INTERVAL '12 months'
GROUP BY d.department_name
ORDER BY total_revenue DESC;
`"
Derrick M. - "SELECT d.departmentname,SUM(o.orderamount) AS total_revenue FROM orders o
JOIN departments d
ON
d.departmentid =o.departmentid
WHERE o.orderdate >= CURRENTDATE - INTERVAL '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
"WITH CTE AS (
SELECT *, ROWNUMBER()OVER(PARTITION BY utxoid ORDER BY transactionid) AS trxrk
FROM transactions
JOIN transaction_inputs
USING (transaction_id)
JOIN utxo
USING (utxo_id)
)
SELECT transaction_id AS InvalidTransactionId
FROM CTE
WHERE sender!=address OR trx_rk > 1
`"
E L. - "WITH CTE AS (
SELECT *, ROWNUMBER()OVER(PARTITION BY utxoid ORDER BY transactionid) AS trxrk
FROM transactions
JOIN transaction_inputs
USING (transaction_id)
JOIN utxo
USING (utxo_id)
)
SELECT transaction_id AS InvalidTransactionId
FROM CTE
WHERE sender!=address OR trx_rk > 1
`"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
"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