"WITH discount AS (
SELECT
name,
type,
CASE
WHEN type = 'Electronic' THEN price * 0.90
WHEN type = 'Clothing' THEN price * 0.80
WHEN type = 'Grocery' THEN price * 0.95
WHEN type = 'Book' THEN price * 0.85
ELSE price
END AS discounted_price
FROM products
)
SELECT
name,
type,
ROUND(discountedprice, 2) AS discountedprice
FROM discount;
`"
Salome L. - "WITH discount AS (
SELECT
name,
type,
CASE
WHEN type = 'Electronic' THEN price * 0.90
WHEN type = 'Clothing' THEN price * 0.80
WHEN type = 'Grocery' THEN price * 0.95
WHEN type = 'Book' THEN price * 0.85
ELSE price
END AS discounted_price
FROM products
)
SELECT
name,
type,
ROUND(discountedprice, 2) AS discountedprice
FROM discount;
`"See full answer
"-- Write your query here
WITH high_value AS(
SELECT user_id
FROM user_sessions
JOIN attribution
ON usersessions.sessionid = attribution.session_id
GROUP BY user_id
HAVING SUM(purchase_value) > 100
ORDER BY SUM(purchase_value) DESC
)
SELECT usersessions.userid, marketing_channel
FROM user_sessions
JOIN high_value
ON usersessions.userid = highvalue.userid
JOIN attribution
ON usersessions.sessionid = attribution.session_id
GROUP BY usersessions.userid
H"
Alina G. - "-- Write your query here
WITH high_value AS(
SELECT user_id
FROM user_sessions
JOIN attribution
ON usersessions.sessionid = attribution.session_id
GROUP BY user_id
HAVING SUM(purchase_value) > 100
ORDER BY SUM(purchase_value) DESC
)
SELECT usersessions.userid, marketing_channel
FROM user_sessions
JOIN high_value
ON usersessions.userid = highvalue.userid
JOIN attribution
ON usersessions.sessionid = attribution.session_id
GROUP BY usersessions.userid
H"See full answer
"
from typing import List
def getnumberof_islands(binaryMatrix: List[List[int]]) -> int:
if not binaryMatrix: return 0
rows = len(binaryMatrix)
cols = len(binaryMatrix[0])
islands = 0
for r in range(rows):
for c in range(cols):
if binaryMatrixr == 1:
islands += 1
dfs(binaryMatrix, r, c)
return islands
def dfs(grid, r, c):
if (
r = len(grid)
"
Rick E. - "
from typing import List
def getnumberof_islands(binaryMatrix: List[List[int]]) -> int:
if not binaryMatrix: return 0
rows = len(binaryMatrix)
cols = len(binaryMatrix[0])
islands = 0
for r in range(rows):
for c in range(cols):
if binaryMatrixr == 1:
islands += 1
dfs(binaryMatrix, r, c)
return islands
def dfs(grid, r, c):
if (
r = len(grid)
"See full answer
"function findPrimes(n) {
if (n < 2) return [];
const primes = [];
for (let i=2; i <= n; i++) {
const half = Math.floor(i/2);
let isPrime = true;
for (let prime of primes) {
if (i % prime === 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.push(i);
}
}
return primes;
}
`"
Tiago R. - "function findPrimes(n) {
if (n < 2) return [];
const primes = [];
for (let i=2; i <= n; i++) {
const half = Math.floor(i/2);
let isPrime = true;
for (let prime of primes) {
if (i % prime === 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.push(i);
}
}
return primes;
}
`"See full answer
"
with youngsuccrate as(
select
strftime('%m', postdate) AS postmonth,
round(sum(issuccessfulpost)*1.0/count(issuccessfulpost),2)as yascrate
from
post
where
userid in (select userid from post_user where age between 0 and 18)
group by
post_month
),
nonyoungsucc_rate as(
select
strftime('%m', postdate) AS postmonth,
round(sum(issuccessfulpost)*1.0/count(issuccessfulpost),2)as nonyasc_rate
from
post
where
user_id in (select"
Bhavna S. - "
with youngsuccrate as(
select
strftime('%m', postdate) AS postmonth,
round(sum(issuccessfulpost)*1.0/count(issuccessfulpost),2)as yascrate
from
post
where
userid in (select userid from post_user where age between 0 and 18)
group by
post_month
),
nonyoungsucc_rate as(
select
strftime('%m', postdate) AS postmonth,
round(sum(issuccessfulpost)*1.0/count(issuccessfulpost),2)as nonyasc_rate
from
post
where
user_id in (select"See full answer
"I'm pretty sure Exponent's answer is wrong.
In the snippet below, they use "pl.name = 'Telephones' to attempt to filter down to the Telephone transactions, but they do this within a LEFT JOIN which means all product_lines rows are returned.
> LEFT JOIN product_lines pl
> ON p.productlineid = pl.id
> AND pl.name = 'Telephones'
Below is my solution. Also, I didn't see anywhere that said the "amount" column was in cents instead of dollars, but I still divided by 100 to be consistent with Exp"
Bradley E. - "I'm pretty sure Exponent's answer is wrong.
In the snippet below, they use "pl.name = 'Telephones' to attempt to filter down to the Telephone transactions, but they do this within a LEFT JOIN which means all product_lines rows are returned.
> LEFT JOIN product_lines pl
> ON p.productlineid = pl.id
> AND pl.name = 'Telephones'
Below is my solution. Also, I didn't see anywhere that said the "amount" column was in cents instead of dollars, but I still divided by 100 to be consistent with Exp"See full answer
"I might be missing something but the solution, seems to be incorrect.
...
, post_pairings AS (
SELECT
ps.user_id,
ps.postseqid AS failpostid,
ps.postseqid + 1 AS nextpostid
FROM post_seq AS ps
WHERE ps.issuccessfulpost IS TRUE
)
-- here ps.issuccessfulpost IS TRUE the condition should be FALSE
-- in that way ps.postseqid is the actual failed post(failpostid)
-- Additionally, at the end the join is assumming that the sequence id is going to match the post_id, wh"
Jaime A. - "I might be missing something but the solution, seems to be incorrect.
...
, post_pairings AS (
SELECT
ps.user_id,
ps.postseqid AS failpostid,
ps.postseqid + 1 AS nextpostid
FROM post_seq AS ps
WHERE ps.issuccessfulpost IS TRUE
)
-- here ps.issuccessfulpost IS TRUE the condition should be FALSE
-- in that way ps.postseqid is the actual failed post(failpostid)
-- Additionally, at the end the join is assumming that the sequence id is going to match the post_id, wh"See full answer
"Select
interface,
Count(case when issuccessfulpost then 1 end) as post_success,
Count() as postattempt,
ROUND((COUNT(CASE WHEN issuccessfulpost THEN 1 END) * 100 / COUNT()), 2) AS postsuccess_rate
from post where interface like 'Iphone%'
group by 1
order by postsuccessrate desc
`"
Richard B. - "Select
interface,
Count(case when issuccessfulpost then 1 end) as post_success,
Count() as postattempt,
ROUND((COUNT(CASE WHEN issuccessfulpost THEN 1 END) * 100 / COUNT()), 2) AS postsuccess_rate
from post where interface like 'Iphone%'
group by 1
order by postsuccessrate desc
`"See full answer
"
Brute Force Two Pointer Solution:
from typing import List
def two_sum(nums, target):
for i in range(len(nums)):
for j in range(i+1, len(nums)):
if nums[i]+nums[j]==target:
return [i,j]
return []
debug your code below
print(two_sum([2, 7, 11, 15], 9))
`"
Ritaban M. - "
Brute Force Two Pointer Solution:
from typing import List
def two_sum(nums, target):
for i in range(len(nums)):
for j in range(i+1, len(nums)):
if nums[i]+nums[j]==target:
return [i,j]
return []
debug your code below
print(two_sum([2, 7, 11, 15], 9))
`"See full answer
"with my_table as (select *
, rownumber() over(order by customerid) as row_index
from customers)
select
customer_id,
customer_name
from my_table
where row_index % 3 = 0"
Marcos G. - "with my_table as (select *
, rownumber() over(order by customerid) as row_index
from customers)
select
customer_id,
customer_name
from my_table
where row_index % 3 = 0"See full answer