Posted by gurpreet, Nov. 29, 2021, 4:12 p.m.
SQL#119
Hi,
I am getting the expected results from following query, but it is not being accepted.
With countries_by_dates as (
SELECT c.date,
b.country,
count(a.booking_id) as bookings
FROM dates c
left join bookings a
on a.date = c.date
left join listings b
on a.listing_id = b.listing_id
where a.date >= '2021-08-01' and a.date <= '2021-08-31'
GROUP BY c.date, b.country
),
rankings as (
SELECT date,
country,
bookings,
row_number() over (partition by date order by bookings desc) as ranking
FROM countries_by_dates
)
SELECT *
FROM rankings
WHERE ranking <=3
I am getting the expected results from following query, but it is not being accepted.
With countries_by_dates as (
SELECT c.date,
b.country,
count(a.booking_id) as bookings
FROM dates c
left join bookings a
on a.date = c.date
left join listings b
on a.listing_id = b.listing_id
where a.date >= '2021-08-01' and a.date <= '2021-08-31'
GROUP BY c.date, b.country
),
rankings as (
SELECT date,
country,
bookings,
row_number() over (partition by date order by bookings desc) as ranking
FROM countries_by_dates
)
SELECT *
FROM rankings
WHERE ranking <=3