sqlserver2008查询某年每个月统计数据
;with cte_tot as(
select col_name,
sum((CAST(col_name AS numeric(18, 2)))) total,
convert(varchar(10),month(time_col))+'月' date
from table_name with(nolock) where convert(varchar(10),year(time_col)) = '2020' group by col_name,month(time_col) ) select col_name, sum(case date when '1月' then total else 0 end) as '1月' , sum(case date when '2月' then total else 0 end) as '2月' , sum(case date when '3月' then total else 0 end) as '3月' , sum(case date when '4月' then total else 0 end) as '4月' , sum(case date when '5月' then total else 0 end) as '5月' , sum(case date when '6月' then total else 0 end) as '6月' , sum(case date when '7月' then total else 0 end) as '7月' , sum(case date when '8月' then total else 0 end) as '8月' , sum(case date when '9月' then total else 0 end) as '9月' , sum(case date when '10月' then total else 0 end) as '10月' , sum(case date when '11月' then total else 0 end) as '11月' , sum(case date when '12月' then total else 0 end) as '12月' from cte_tot where col_name is not null group by col_name
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
2018-05-27 MySQL系列之三查询优化