返回信息流试题二:从1个table中产生报表, generate report from 1 table
情况与上题相似,但是数据在1个table里:
Data stored in 1 table instead of 2 tables
Accounts
Cus_ID Acct_No Acct_Type
1 10001 Checking
1 50001 Savings
2 10002 Checking
3 50002 Savings
写SQL语句,产生这样的报表(与上题相同的报表):
Use SQL statement to generate this report
Cus_ID Checking_Account Savings_Account
1 10001 50001
2 10002
3 50002
这是一条镜像帖。来源:北邮人论坛 / database / #4943同步于 2010/10/25
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Database机器人发帖
请教SQL的一个题目
CLegend
2010/10/25镜像同步6 回复
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
plsql经典测试题~
【 在 CLegend (皮波) 的大作中提到: 】
: 试题二:从1个table中产生报表, generate report from 1 table
: 情况与上题相似,但是数据在1个table里:
: Data stored in 1 table instead of 2 tables
: ...................
【 在 doubleKO 的大作中提到: 】
: plsql经典测试题~
: 【 在 CLegend (皮波) 的大作中提到: 】
: : 试题二:从1个table中产生报表, generate report from 1 table
: ...................
哦,谢谢,我以为看了SQL就可以做了。
/*
情况与上题相似,但是数据在1个table里:
Data stored in 1 table instead of 2 tables
Accounts
Cus_ID Acct_No Acct_Type
1 10001 Checking
1 50001 Savings
2 10002 Checking
3 50002 Savings
写SQL语句,产生这样的报表(与上题相同的报表):
Use SQL statement to generate this report
Cus_ID Checking_Account Savings_Account
1 10001 50001
2 10002
3 50002
*/
create table accounts(
cus_id char(2),
acct_id char(6),
acct_type char(10)
);
insert into accounts values('1','10001','Checking');
insert into accounts values('1','50001','Savings');
insert into accounts values('2','10002','Checking');
insert into accounts values('3','50002','Savings');
select cus_id,sum(cast(case when acct_type='Checking'
then acct_id else null end as int)) as Checking_Account,
sum(cast(case when acct_type='Savings'
then acct_id else null end as int)) as Savings_Account
from accounts
group by cus_id
【 在 CLegend 的大作中提到: 】
: 哦,谢谢,我以为看了SQL就可以做了。
【 在 newtj 的大作中提到: 】
: sql server的写法,oracle的话,把cast as int函数改成to_number()就行
: --
谢谢你