當前位置:首頁 » 編程語言 » sql報表統計

sql報表統計

發布時間: 2023-06-05 03:27:36

sql 報表統計 總計小計

哥們兒,你這寫的太亂了。。整理一下格式吧。

⑵ sqlserver 統計報表的 sql語句怎麼寫


--動態語句
declare@sqlvarchar(8000)
select@sql=isnull(@sql+'],[','')+NAMEfromT_CSDN_ONEgroupbyNAME
set@sql='['+@sql+']'
EXEC('select*from(select*fromT_CSDN_ONE)apivot(SUM(ISNULL(MONERY,0)forNAMEin('+@sql+'))b')

⑶ SQL 統計報表

-- create sample table
create table tab1 (id int, output_style char(1), amount int, output_date date);

insert into tab1 values(1,'D',1000,'2009-11-12');
insert into tab1 values(2,'C',1000,'2009-11-12');
insert into tab1 values(3,'G',1000,'2009-12-12');
insert into tab1 values(4,'Z',1000,'2010-01-01');
insert into tab1 values(5,'D',1300,'2009-11-12');
insert into tab1 values(6,'C',1400,'2009-11-12');
insert into tab1 values(7,'G',2000,'2009-12-12');
insert into tab1 values(8,'Z',1000,'2010-01-01');

-- query
select concat(year(output_date), month(output_date)) as yearmonth,
sum(case when output_style='C' then amount else 0 end) as C_Amount,
sum(case when output_style='G' then amount else 0 end) as G_Amount,
sum(case when output_style='Z' then amount else 0 end) as Z_Amount,
sum(case when output_style='D' then amount else 0 end) as D_Amount from tab1 group by output_date

熱點內容
cmd運行python程序 發布:2025-09-19 08:16:07 瀏覽:287
如何給你的安卓手機正確充電 發布:2025-09-19 08:15:18 瀏覽:840
vs2010怎麼寫c語言 發布:2025-09-19 07:31:05 瀏覽:870
除了證券外還有哪些投資配置 發布:2025-09-19 07:01:48 瀏覽:77
android把函數 發布:2025-09-19 07:01:04 瀏覽:283
垃圾站源碼 發布:2025-09-19 06:42:30 瀏覽:156
java按鈕事件 發布:2025-09-19 06:29:45 瀏覽:459
文件夾用處 發布:2025-09-19 06:21:42 瀏覽:90
php數組位置 發布:2025-09-19 06:06:45 瀏覽:867
伺服器光口配ip 發布:2025-09-19 05:48:37 瀏覽:848