Quotes help make search much faster. Example: "Practice Makes Perfect"

Tuesday, May 9, 2017

Codecademy SQL: Analyzing Business Metrics Exercise 9 of 14


--first answer

with daily_revenue as (
  select
    date(created_at) as dt,
    round(sum(price), 2) as rev
  from purchases
  where refunded_at is null
  group by 1
),
daily_players as (
  select
    date(created_at) as dt,
    count(distinct user_id) as players
  from gameplays
  group by 1
)
select * from daily_players order by dt;

--second answer

with daily_revenue as (
  select
    date(created_at) as dt,
    round(sum(price), 2) as rev
  from purchases
  where refunded_at is null
  group by 1
),
daily_players as (
  select
    date(created_at) as dt,
    count(distinct user_id) as players
  from gameplays
  group by 1
)
select
  daily_revenue.dt,
  daily_revenue.rev / daily_players.players
from daily_revenue
  join daily_players using (dt);

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts