最近遇到按表里得交付时间换成季度取统计,如下:
select sp.Id,sp.title,QUARTER(sp.expected_delivery_time) dateStr,CONCAT(DATE(MIN(sp.expected_delivery_time)),'至',DATE(MAX(sp.expected_delivery_time))) dateStr2,sp.DemandType,sp.IndustryGroup,sp.IndustrySubGroup,sp.IndustrySubGroupName,sp.IndustrySpecific,sp.IndustrySpecificName,COUNT(bc.Id) CompanyNum,GROUP_CONCAT(bc.CompanyName) as companyNames,bc.Cityfrom supd_demand_info sp INNER JOIN base_companyinfo bc on sp.CreatorId=bc.UserId Where sp.IsDeleted=0 -- and sp.status='Published' and sp.expected_delivery_time > NOW()GROUP BY sp.IndustrySubGroup ,sp.CityCode,QUARTER(sp.expected_delivery_time) ORDER BY sp.expected_delivery_time desc
结果如下:
上面dateStr是统计出得当前属于那个季度,dateStr2是交付时间最小和最大值 (这里可能不太合理,因为之前得逻辑现在变了,直接返回一个交付时间就可以了)