[英]How to get min / max date in the count , group by query?
In SQL , How to get min / max date in the count , group by query? 在SQL中,如何获取count,通过查询分组的最小/最大日期?
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) 预期输出..以及SourceId,Count,StartDate(Minimum),EndDate(Maximum)
add the aggregation column you need 添加您需要的聚合列
select SourceId
, Count(FileName) as TotalFileCount
, min(RecevidDate) InitialReceiveDate
, max(RecevidDate) LastReceiveDate
from mytable
group by SourceId
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.