win_by_all_aggregate.sql 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* postgres can not */
  2. /* syntax version 1 */
  3. use plato;
  4. $data = (select cast(key as uint32) as age, cast(subkey as uint32) as region, value as name from Input);
  5. -- insert into Output
  6. select
  7. region,
  8. name,
  9. sum(age) over w1 as sum,
  10. min(age) over w1 as min,
  11. max(age) over w1 as max,
  12. count(age) over w1 as count,
  13. count(*) over w1 as count_all,
  14. count_if(age>20) over w1 as count_if,
  15. some(age) over w1 as some,
  16. bit_and(age) over w1 as bit_and,
  17. bit_or(age) over w1 as bit_or,
  18. bit_xor(age) over w1 as bit_xor,
  19. bool_and(age>20) over w1 as bool_and,
  20. bool_or(age>20) over w1 as bool_or,
  21. avg(age) over w1 as avg,
  22. aggr_list(age) over w1 as `list`,
  23. min_by(age, name) over w1 as min_by,
  24. max_by(age, name) over w1 as max_by,
  25. nanvl(variance(age) over w1, -999.0) as variance,
  26. nanvl(stddev(age) over w1, -999.0) as stddev,
  27. nanvl(populationvariance(age) over w1, -999.0) as popvar,
  28. nanvl(stddevpopulation(age) over w1, -999.0) as popstddev,
  29. histogram(age) over w1 as hist,
  30. median(age) over w1 as median,
  31. percentile(age, 0.9) over w1 as perc90,
  32. aggregate_by(age, aggregation_factory("count")) over w1 as aggby
  33. from $data
  34. window w1 as (partition by region order by name desc)
  35. order by region, name desc
  36. ;