已经写过查询以查找每个客户发出的许多订单? 我现在可以在不使用Group by子句的情况下编写相同的查询吗? 使用某种子查询并加入。
SELECT c.CustomerID, count(si.CustomerID)
from Customer c LEFT OUTER join SalesInvoice si
ON si.CustomerID = c.CustomerID
GROUP by c.CustomerID
答案 0 :(得分: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