[SQL ] mssql or postgresql 语法请教?

楼主: superttl (ttl)   2017-01-23 12:48:06
数据库名称:mssql or postgresql
各位数据库的前辈大家好,小弟在撰写程式时需要用到select 小计及合计及总计的
问题,再使用 google 及站内讨论有搜寻到相关的讨论但是套用在现况一直无法解出来,
以下是小弟的测试资料(以 postgresql为例)。
create table test_tbl(
bank_code varchar(7),
con_amt1 int8,
con_amt2 int8,
con_amt3 int8,
con_type char(1),
col_type char(2)
);
nsert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0040037',500,0,300,'H','00');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0040037',300,0,300,'H','00');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0040037',700,0,0,'H','21');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0041241',300,0,100,'H','21');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0041241',300,0,150,'H','14');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0041241',100,0,100,'F','14');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0041241',100,0,50,'F','14');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0041241',50,0,20,'L','14');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0041241',50,0,30,'L','14');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0050016',400,0,300,'H','00');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0050016',400,0,300,'H','00');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0050016',300,0,0,'H','21');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0050016',200,0,100,'H','21');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0050027',200,0,150,'H','14');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0050027',150,0,100,'F','14');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0050027',120,0,50,'F','14');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0050027',60,0,20,'L','14');
insert into test_tbl(bank_code,con_amt1,con_amt2,con_amt3,con_type,col_type)
values('0050027',60,0,30,'L','14');
资料输出如下:
select bank_code, con_type,col_type,con_amt1,con_amt2,con_amt3 from test_tbl;
bank_code | con_type | col_type | con_amt1 | con_amt2 | con_amt3

Links booklink

Contact Us: admin [ a t ] ucptt.com