Reputation: 3492
In SQL , How to get min / max date in the count , group by query?
Query :
-- This doesn't give Min and Max date received for the file
;with cte as
(
select SourceId,Count(FileName) as TotalFileCount
from mytable
group by SourceId
)
select * from cte
order by TotalFileCount desc
Expected output .. is along with the SourceId, Count, StartDate(Minimum), EndDate(Maximum)
Upvotes: 1
Views: 688
Reputation: 133360
add the aggregation column you need
select SourceId
, Count(FileName) as TotalFileCount
, min(RecevidDate) InitialReceiveDate
, max(RecevidDate) LastReceiveDate
from mytable
group by SourceId
Upvotes: 3