Tag Info

New answers tagged

0

To get all gapless time ranges per contact summed up: SELECT max(order_year) AS order_year, contact, count(*) AS consecutive_years FROM ( SELECT *, order_year - row_number() OVER (PARTITION BY contact ORDER BY order_year) AS grp FROM orders ) sub GROUP BY contact, grp ORDER BY contact, 1; To get ...


3

So I've built a short SQL script to do this operation, based on the original sample input data: Order_year, Contact 2015, 123 2014, 123 2013, 123 2011, 123 2010, 123 2015, 234 2014, 234 2011, 234 The script is as follows: WITH RECURSIVE ranked_order AS( SELECT order_year, contact, 1 AS counter FROM orders UNION SELECT orders.order_year, ...



Top 50 recent answers are included