数据库分表存储查询

本文详细介绍了一种使用SQL的UNION操作符进行复杂数据查询的方法,通过联合多个表中相同borrow_account_id的数据,实现对特定贷款ID和期数的还款信息的高效检索。此方法适用于需要从多个相似结构的表中获取汇总数据的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

select * from
(select * from credit.credit_repayment_0
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_1
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_2
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_3
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_4
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_5
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_6
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_7
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_8
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_9
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_10
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_11
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_12
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_13
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_14
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_15
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_16
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_17
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_18
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_19
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_20
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_21
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_22
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_23
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_24
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_25
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_26
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_27
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_28
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_29
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_30
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_31
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_32
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_33
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_34
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_35
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_36
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_37
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_38
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_39
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_40
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_41
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_42
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_43
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_44
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_45
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_46
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_47
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_48
where borrow_account_id =‘154201911650900104’
UNION
select * from credit.credit_repayment_49
where borrow_account_id =‘154201911650900104’) j where loan_id =282828676422545408 and term_num=1;

可以统一创建视图,查询方便

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值