12aggr.mql 860 B

12345678910111213141516171819202122232425262728293031
  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. **/
  15. ;
  16. -- 3. 子查询 group by
  17. 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
  18. /**
  19. output()
  20. **/
  21. ;
  22. -- 4. 子查询嵌套的聚合
  23. select max(s_value) from /test/aaa/test_subquery where s_type in (select s_type from /test/aaa/test_subquery)
  24. /**
  25. output()
  26. **/
  27. ;