2.1 COUNT DISTINCT
Find the number of customers who place an order in each month:
SQL
SELECT count(DISTINCT CustomerID) num,year(OrderDate) years,
month(OrderDate) months
FROM Orders
WHERE OrderDate>='2022-01-01' and EmployeeID=5
GROUP BY year(OrderDate), month(OrderDate)
ORDER BY years,months
SPL
A | |
---|---|
1 | >st=date(“2022-01-01”), start=days@o(st) |
2 | =file(“Orders.ctx”).open().cursor@x(OrderDate,CustomerID;OrderDate>=start && EmployeeID==5) |
3 | =A2.groups(year(OrderDate):years,month(OrderDate):months;icount(CustomerID):num) |
A3 Use icount function to calculate the number of distinct members.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL