当前位置:首页 » 编程语言 » 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

热点内容
安卓apk反编译修改服务器 发布:2025-07-14 17:23:33 浏览:859
threadc语言 发布:2025-07-14 17:13:23 浏览:166
rap加密 发布:2025-07-14 17:10:28 浏览:675
英雄联盟和吃鸡哪个吃配置 发布:2025-07-14 17:01:32 浏览:97
访问罗晋 发布:2025-07-14 17:00:04 浏览:396
逍遥西游辅助脚本 发布:2025-07-14 16:56:57 浏览:585
java默认类 发布:2025-07-14 16:51:03 浏览:279
术后解压 发布:2025-07-14 16:39:47 浏览:661
手机版我的世界怎么输入服务器ip 发布:2025-07-14 16:25:21 浏览:722
pythonsysstdout 发布:2025-07-14 16:15:29 浏览:197