avg.sql 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* syntax version 1 */
  2. /* postgres can not */
  3. pragma EmitAggApply;
  4. $t = SELECT * FROM AS_TABLE([<|key: 1, value: 2|>,<|key: 1, value: 3|>]);
  5. $p =
  6. SELECT
  7. key,avg(value) as a
  8. FROM $t
  9. GROUP BY
  10. key
  11. with combine
  12. ;
  13. $p = PROCESS $p;
  14. --select FormatType(TypeOf($p));
  15. select * from $p;
  16. $p = SELECT
  17. key,avg(a) as a
  18. FROM $p
  19. GROUP BY
  20. key
  21. with combinestate
  22. ;
  23. $p = PROCESS $p;
  24. --select FormatType(TypeOf($p));
  25. select * from $p;
  26. $p = SELECT
  27. key,avg(a) as a
  28. FROM $p
  29. GROUP BY
  30. key
  31. with mergestate
  32. ;
  33. $p = PROCESS $p;
  34. --select FormatType(TypeOf($p));
  35. select * from $p;
  36. $p1 = SELECT
  37. key,avg(a) as a
  38. FROM $p
  39. GROUP BY
  40. key
  41. with mergefinalize
  42. ;
  43. $p1 = PROCESS $p1;
  44. --select FormatType(TypeOf($p1));
  45. select * from $p1;
  46. $p2 = SELECT
  47. key,avg(a) as a
  48. FROM (select key, just(a) as a from $p)
  49. GROUP BY
  50. key
  51. with mergemanyfinalize
  52. ;
  53. $p2 = PROCESS $p2;
  54. --select FormatType(TypeOf($p2));
  55. select * from $p2;
  56. $p3 =
  57. SELECT
  58. key,avg(value) as a
  59. FROM $t
  60. GROUP BY
  61. key
  62. with finalize
  63. ;
  64. $p3 = PROCESS $p3;
  65. --select FormatType(TypeOf($p));
  66. select * from $p3;