Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --explain
- with summary as (
- select
- m.id,
- m."externalId",
- m."from",
- m.to,
- m.title,
- m."dateReceived",
- m.removed,
- row_number() over w_date as rank,
- count(*) over w_no_date as count,
- sum(cast(m.removed as int)) over w_no_date as "totalRemoved",
- count(*) over() as full_count
- from public."Mail" m
- -- having rank = 1
- window
- w_date as (partition by m.title order by m."dateReceived" desc),
- w_no_date as (partition by m.title)
- )
- select
- *,
- COUNT(*) over() as total_grouped
- from summary s
- where rank = 1
- --order by s.title, s."dateReceived" desc
- order by s."dateReceived" desc
- limit 10 offset 0
Advertisement
Add Comment
Please, Sign In to add comment