What do you think?
Rate this book


357 pages, Paperback
Published October 19, 2021
GROUP BY
1,
2,
3
with txs(id, amount) as (
values
(1, 100),
(2, 280),
(3, 100)
)
select
count(id) as count_id,
sum(amount) as sum_amount,
round(amount, -2) / 100 as bucket
from
txs
group by
bucket;
with customer(id, updated_ts) as (
values
(1, '2000-01-01'::date),
(1, '2000-01-02'::date),
(1, '2000-01-03'::date),
(1, '2000-01-04'::date),
(1, '2000-01-05'::date),
(2, '2000-01-05'::date)
),
ranked as (
select
*,
row_number() over (partition by id order by updated_ts desc) as rn
from
customer
)
-- Deduplicate.
select
'Most Recent' as kind,
*
from
ranked
where
rn = 1
union all
-- Show Duplicates.
select
'Duplicate',
*
from
ranked
where
1 < rn
;