3.4 有序 DISTINCT

SQL

SELECT DISTINCT month(OrderDate)
FROM Orders
WHERE OrderDate>='2021-01-01' and OrderDate<='2021-12-31' and EmployeeID=5

SPL

A
1 >st=date(“2021-01-01”), et=date(“2021-12-31”), start=days@o(st), end=days@o(et)
2 =file(“Orders_Time.ctx”).open().cursor@m(OrderDate;OrderDate>=start && OrderDate <=end && EmployeeID==5;2)
3 =A2.groups@o(month(OrderDate):months)

A3 @o 表示有序分组,只和前一行对比


SQL

WITH m AS(
  SELECT DISTINCT CustomerID,month(OrderDate) months
  FROM Orders
  WHERE OrderDate>='2021-01-01' and OrderDate<='2021-12-31')
SELECT months,count(*) num
FROM m 
GROUP BY months

SPL

A
1 >st=date(“2021-01-01”), et=date(“2021-12-31”), start=days@o(st), end=days@o(et)
2 =file(“Orders_Account.ctx”).open().cursor@m(CustomerID, OrderDate;OrderDate>=start && OrderDate <=end;2)
3 =A2.group@1(CustomerID,month(OrderDate))
4 =A3.groups(month(OrderDate):months;count(1):num)

A3 当数据按分组字段有序时,用 group@1 实现 DISTINCT 计算,在遍历过程中把与上一条不相同的记录作为游标逐步返回,即使内存放不下也不必做缓存,可以实现结果集超出内存容量时的 DISTINCT 运算。cs.group() 默认数据已经按分组字段有序了

以下是广告时间

对润乾产品感兴趣的小伙伴,一定要知道软件还能这样卖哟性价比还不过瘾? 欢迎加入好多乾计划。
这里可以低价购买软件产品,让已经亲民的价格更加便宜!
这里可以销售产品获取佣金,赚满钱包成为土豪不再是梦!
这里还可以推荐分享抢红包,每次都是好几块钱的巨款哟!
来吧,现在就加入,拿起手机扫码,开始乾包之旅



嗯,还不太了解好多乾?
猛戳这里
玩转好多乾