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

熱點內容
我配置很高了ae為什麼卡 發布:2025-05-17 14:54:50 瀏覽:167
python數據分析實戰pdf 發布:2025-05-17 14:49:42 瀏覽:950
海瀾之家廣告腳本 發布:2025-05-17 13:56:06 瀏覽:32
手文件夾恢復 發布:2025-05-17 13:53:32 瀏覽:995
linux怎麼看進程 發布:2025-05-17 13:53:30 瀏覽:305
thinkphp欄位緩存 發布:2025-05-17 13:52:01 瀏覽:577
山靈app安卓版如何設置 發布:2025-05-17 13:51:49 瀏覽:390
帆布壓縮袋 發布:2025-05-17 13:26:27 瀏覽:462
c語言16進製表示方法 發布:2025-05-17 13:11:25 瀏覽:484
ftp單位 發布:2025-05-17 13:10:03 瀏覽:146