我可以通过查询编写这个组而不用group by吗?

时间:2022-01-13 20:44:16

I've written query to find HOw many orders placed by each customer? I would like to now can i write same querying without using Group by clause? using somekind of subquery and join.

我写过查询,找到每个客户下的许多订单?我想现在可以在不使用Group by子句的情况下编写相同的查询吗?使用somekind子查询并加入。

SELECT c.CustomerID, count(si.CustomerID)
from Customer c LEFT OUTER join SalesInvoice si
ON si.CustomerID = c.CustomerID
GROUP by c.CustomerID

1 个解决方案

#1


5  

SELECT c.CustomerID, count(si.CustomerID) OVER(PARTITION BY c.CustomerID)
from Customer c LEFT OUTER join SalesInvoice si
ON si.CustomerID = c.CustomerID

#1


5  

SELECT c.CustomerID, count(si.CustomerID) OVER(PARTITION BY c.CustomerID)
from Customer c LEFT OUTER join SalesInvoice si
ON si.CustomerID = c.CustomerID