1、查询每个账户的折人民币余额,返回:账户代号、账户名称、币种、开户机构、账户状态、账户折人民币余额
select
a.*,b.zhye*c.hl as '折人民币余额'
from t_ckzh a
join t_zhye b on a.zhdh = b.zhdh
join t_hl c on a.bz = c.bz
2、查询账户折人民币余额最大的账户信息,返回:账户代号、账户名称、币种、开户机构、账户余额
select
a.*,b.zhye*c.hl as '折人民币余额'
from t_ckzh a
join t_zhye b on a.zhdh = b.zhdh
join t_hl c on a.bz = c.bz
ORDER BY b.zhye*c.hl desc
3、查询开户账户数少于2个的机构相关信息,返回:开户机构、开户账户数、存款总余额(折人民币)
SELECT
a.khjg,COUNT(*) as '开户账户数',b.zhye*c.hl as '存款总余额'
from t_ckzh a
join t_zhye b on a.zhdh = b.zhdh
join t_hl c on a.bz = c.bz
GROUP BY a.khjg
HAVING count(*) <2
4、假设账户状态=0,表示“正常账户”,账户状态=2表示“销户账户”,请查询销户总余额,返回:销户总余额
select
sum(b.zhye*c.hl) as '销户总金额'
from t_ckzh a
join t_zhye b on a.zhdh = b.zhdh
join t_hl c on a.bz = c.bz
GROUP BY a.zhzt
HAVING a.zhzt = 0
5、假设账户状态=0,表示“账户正常”,账户状态=2表示“账户销户”,请查询不同机构下,账户不同状态的余额,返回:开户机构、正常账户余额之和、销户账户余额之和
select
c.khjg,(select count(t.zhye)
from t_zhye z
where
z.zhdh=(select c.zhdh from t_ckzh where c.zhzt=0)) 销户账户余额之和,
(select
count(t.zhye)
from t_zhye z
where
z.zhdh=(select c.zhdh from t_ckzh where c.zhzt=2)) 正常账户余额之和
from t_ckzh c
6、账户余额(折人民币)高于AAA账户的账户信息,返回账户代号、账户名称、币种、开户机构、账户余额
select
a.*,b.zhye*c.hl as '账号余额'
from t_ckzh a
join t_zhye b on a.zhdh = b.zhdh
join t_hl c on a.bz = c.bz
where b.zhye*c.hl >(
select
y.zhye*z.hl
from t_ckzh x
join t_zhye y on x.zhdh = y.zhdh
join t_hl z on x.bz = z.bz
where x.zhdh = 'AAA'
)