12aggr.mql 932 B

1234567891011121314151617181920212223242526272829303132333435
  1. -- ============================================================
  2. -- 子查询+聚合测试
  3. -- ============================================================
  4. -- 1. 子查询中用聚合函数
  5. select * from /test/aaa/test_subquery where s_value > (select avg(s_value) from /test/aaa/test_subquery)
  6. /**
  7. output()
  8. **/
  9. ;
  10. -- 2. 子查询中用 count
  11. select * from /test/aaa/test_subquery where s_type in (select s_type from /test/aaa/test_subquery group by s_type having count(*) > 1)
  12. /**
  13. output()
  14. match("subq_001")
  15. match("subq_002")
  16. match("subq_003")
  17. match("subq_004")
  18. **/
  19. ;
  20. -- 3. 子查询 group by
  21. select s_type, count(*) from /test/aaa/test_subquery where s_value > (select min(s_value) from /test/aaa/test_subquery where s_type='type_x') group by s_type
  22. /**
  23. output()
  24. **/
  25. ;
  26. -- 4. 子查询嵌套的聚合
  27. select max(s_value) from /test/aaa/test_subquery where s_type in (select s_type from /test/aaa/test_subquery)
  28. /**
  29. output()
  30. **/
  31. ;