1.with
- sql statement
WITH type as (select DISTINCT on(kbid) * from rptsvc_leak_event ORDER BY kbid,event_time desc) SELECT leak_type,count(*) FROM type GROUP BY leak_type
- Explanation
- Brackets statement: select DISTINCT on (kbid) * from rptsvc_leak_event ORDER BY kbid, event_time desc, descending in accordance with event_time, and for kbid duplicates removed, returns all content. Note: Be sure to add after order by kbid, otherwise an error.
-
- with parentheses after use as the sql statement assigned to type, that is, type a new table.
- This entire statement can be replaced with:
SELECT leak_type,count(*) FROM (select DISTINCT on(kbid) * from rptsvc_leak_event ORDER BY kbid,event_time desc) as type GROUP BY leak_type,
The same should also pay attention plus as, otherwise statements are incorrect
2.row_number() over
- sql statement
select *, row_number() over(partition by gid,mid,kbid ORDER BY event_time desc ) from rptsvc_leak_event
- Explanation
- row_number () over (partition by gid, mid, kbid ORDER BY event_time desc): according kib, gid, mid packet, and according event_time descending order, returns all content