SQL Server Query for distinct rows
sql, sql-server
Solution
This is a bit tricky. You want to count the first date a customer appears and then do the aggregation:
select mindate, count(*) as NumNew
from (select CustId, min(Date) as mindate
from table t
group by CustId
) c
group by mindate
Problem
How do I query for distinct customers? Here's the table I have.. ``` CustID DATE PRODUCT ======================= 1 Aug-31 Orange 1 Aug-31 Orange 3 Aug-31 Apple 1 Sept-24 Apple 4 Sept-25 Orange ``` This is what I want. ``` # of New Customers DATE ======================================== 2 Aug-31 1 Sept-25 ``` Thanks!