1.16 分组:用汇总值筛选分组

 

有如下日产品销售额表,找出日销售总额超过 30 万的日期有哪些:

OrderDate ProductName Sales
1996-07-04 Aniseed Syrup 51919.0000
1996-07-04 Chai 21169.0000
1996-07-04 Chang 23154.0000
1996-07-04 Chef Anton’s Cajun Seasoning 20307.0000
1996-07-04 Chef Anton’s Gumbo Mix 97636.0000

脚本:

A
1 =connect(“db”)
2 =A1.query@x(“select * from ProductDailySales”)
3 =A2.groups(OrderDate;sum(Sales):TotalSales)
4 =A3.select(TotalSales>300000)

A1 连接数据库
A2 查询产品日销售额表
A3 按订单日分组统计总销售额
A4 选出日总销售额大于 30 万的记录

运行结果:

OrderDate TotalSales
1996/7/10 394565
1996/7/11 402883
1996/7/22 331978
1996/8/1 304470
1996/8/6 306196