mysqlsql汇总查询将两个结果集合并⼀⾏展⽰建表语句:
CREATE TABLE TB_TABLE (
ID char(32) NOT NULL COMMENT ‘主键’,
BIZ_NUM varchar(30) DEFAULT NULL COMMENT ‘业务编号’,
mysql面试题汇总>gulpBIZ_AMT int(11) DEFAULT NULL COMMENT ‘⾦额’,
TYPE char(11) DEFAULT NULL COMMENT ‘类型,01-流⼊;02-流出’,
PRIMARY KEY (ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=‘信息表’;
INSERT INTO TB_TABLE VALUES(‘1’,‘111’,120,‘01’);
INSERT INTO TB_TABLE VALUES(‘2’,‘111’,80,‘02’);
INSERT INTO TB_TABLE VALUES(‘3’,‘111’,30,‘01’);
dubbo是什么协议javascript中怎样定义数组
INSERT INTO TB_TABLE VALUES(‘4’,‘222’,70,‘01’);
INSERT INTO TB_TABLE VALUES(‘5’,‘222’,50,‘02’);
预期输出效果:
业务编号 流⼊⾦额 流出⾦额
111 150 80
222 70 50
⽅法⼀:
select
t.biz_num,
sum(case pe=‘01’ then t.biz_amt end) as bizAmtIn,
sum(case pe=‘02’ then t.biz_amt end) as bizAmtOut
虚拟机里oralce11g安装教程from tb_table t
pe in (‘01’,‘02’)
group by t.biz_num
⽅法⼆:
select
t.biz_num,
开发者工具有什么作用sum(pe=‘01’,t.biz_amt,0)) as bizAmtIn,
sum(pe=‘02’,t.biz_amt,0)) as bizAmtOut
from tb_table t
pe in (‘01’,‘02’)
group by t.biz_num;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论