當前位置:首頁 » 編程語言 » 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

熱點內容
寫入設備緩存 發布:2025-07-01 04:37:35 瀏覽:429
小雞g4怎麼連安卓 發布:2025-07-01 04:37:25 瀏覽:353
黃金線主圖源碼 發布:2025-07-01 04:35:38 瀏覽:295
阿里輕量伺服器有固定IP嗎 發布:2025-07-01 04:30:27 瀏覽:504
電腦什麼配置要合適 發布:2025-07-01 04:24:15 瀏覽:164
哪個安卓恢復工具不要錢 發布:2025-07-01 04:21:54 瀏覽:740
sql加空格 發布:2025-07-01 04:09:38 瀏覽:578
如何關閉ftp防篡改 發布:2025-07-01 04:09:04 瀏覽:89
頑固的緩存 發布:2025-07-01 03:28:23 瀏覽:114
u盤插安卓手機上怎麼加密 發布:2025-07-01 03:09:19 瀏覽:91