15aggr.mql 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. -- ============================================================
  2. -- sum/avg/min/max 聚合函数测试
  3. -- ============================================================
  4. -- 1. sum
  5. select sum(a_amount) from /test/aaa/test_aggr
  6. /**
  7. output()
  8. match("sum(a_amount)","2000")
  9. **/
  10. ;
  11. -- 2. avg (int)
  12. select avg(a_int) from /test/aaa/test_aggr
  13. /**
  14. output()
  15. **/
  16. ;
  17. -- 3. avg (float)
  18. select avg(a_float) from /test/aaa/test_aggr
  19. /**
  20. output()
  21. **/
  22. ;
  23. -- 4. avg (double)
  24. select avg(a_double) from /test/aaa/test_aggr
  25. /**
  26. output()
  27. **/
  28. ;
  29. -- 5. min
  30. select min(a_amount) from /test/aaa/test_aggr
  31. /**
  32. output()
  33. match("min(a_amount)","100")
  34. **/
  35. ;
  36. -- 6. max
  37. select max(a_amount) from /test/aaa/test_aggr
  38. /**
  39. output()
  40. match("max(a_amount)","500")
  41. **/
  42. ;
  43. -- 7. 多聚合函数同时使用
  44. select sum(a_amount), avg(a_float), min(a_int), max(a_int) from /test/aaa/test_aggr
  45. /**
  46. output()
  47. **/
  48. ;
  49. -- 8. 带条件的聚合
  50. select sum(a_amount) from /test/aaa/test_aggr where a_category='category_a'
  51. /**
  52. output()
  53. match("sum(a_amount)","450")
  54. **/
  55. ;
  56. -- 9. 聚合空结果集
  57. select sum(a_amount) from /test/aaa/test_aggr where a_int=99999
  58. /**
  59. output()
  60. **/
  61. ;