复杂的sql参考(3)
SELECT
apply.assets_code,
apply.loan_apply_code,
cust.cust_name,
cust.id_no,
cust.mobile,
platform.platform_name,
product.product_name,
subproduct.product_sub_name,
(
CASE
WHEN assets.assets_type = '1' THEN
'消费分期'
WHEN assets.assets_type = '2' THEN
'物流金融'
WHEN assets.assets_type = '3' THEN
'汽车金融'
WHEN assets.assets_type = '4' THEN
'农村金融'
WHEN assets.assets_type = '5' THEN
'经营周转贷'
WHEN assets.assets_type = '6' THEN
'保险金融'
WHEN assets.assets_type = 7 THEN
'信用分期'
END
) AS assets_type,
apply.loan_amount,
apply.init_period,
FORMAT(apply.contract_rate * 100.0,2) as contract_rate,
(
SELECT
SUM(principal_amt)
FROM
aim_t_loan_repay_process
WHERE
assets_code = apply.assets_code
-- ORDER BY
-- id DESC
-- LIMIT 0,
-- 1
) AS cur_not_balance,
(
CASE
WHEN apply.repayment_type_code=1 then '按月付息,到期还本(按日计)'
WHEN apply.repayment_type_code=2 then '按月付息,到期还本(按自然月计)'
WHEN apply.repayment_type_code=3 then '到期一次性还本付息'
WHEN apply.repayment_type_code=4 then '等额本息'
WHEN apply.repayment_type_code=5 then '等额本金'
END
) as repayment_type_code,
apply.create_time as loan_apply_time,
(
CASE
WHEN apply.approve_status='B001' then '待初审'
WHEN apply.approve_status='B002' then '待终审'
WHEN apply.approve_status='B003' then '人工通过'
WHEN apply.approve_status='B004' then '人工拒绝'
WHEN apply.approve_status='B005' then '系统通过'
WHEN apply.approve_status='B006' then '系统拒绝'
END
) as approve_status,
(
CASE
WHEN apply.apply_status='A001' then '待审核'
WHEN apply.apply_status='A002' then '撤单'
WHEN apply.apply_status='A003' then '初审拒绝'
WHEN apply.apply_status='A004' then '系统拒绝'
WHEN apply.apply_status='A005' then '待准售'
WHEN apply.apply_status='A006' then '复核'
WHEN apply.apply_status='A007' then '销售'
WHEN apply.apply_status='A008' then '放款中'
WHEN apply.apply_status='A009' then '贷中'
WHEN apply.apply_status='A010' then '结案'
WHEN apply.apply_status='A011' then '内部取消'
WHEN apply.apply_status='A013' then '终审拒绝'
WHEN apply.apply_status='A014' then '审核完成'
END
) as apply_status,
audit1.create_time AS first_create_time,
audit1.approver_name AS first_approver_name,
audit1.comments AS first_comments,
audit1.reason_first AS first_reason_first,
audit1.reason_second AS first_reason_second,
audit2.create_time AS second_create_time,
audit2.approver_name AS second_approver_name,
audit2.comments AS second_comments,
audit2.reason_first AS second_reason_first,
audit2.reason_second AS second_reason_second,
(
CASE
WHEN apply.is_open=0 then '未开户'
WHEN apply.is_open=1 then '已开户'
END
) as is_open,
account.create_time AS account_finish_time,
IF (
apply.agreement_confirm_time IS NULL
OR apply.agreement_confirm_time = '',
'未确认',
'已确认'
) AS is_confirm,
apply.agreement_confirm_time,
apply.approve_sale_time,
assets.loan_time,
(
SELECT
repay_date
FROM
aim_t_loan_repay_plan plan
WHERE
plan.assets_code = apply.assets_code
AND plan.deleted = '0'
ORDER BY
id DESC
LIMIT 0,
1
) AS repay_date,
(
CASE
WHEN (
apply.apply_status = 'A014'
AND apply.is_open = 0
) THEN
'待开户'
WHEN (
apply.apply_status = 'A014'
AND (
apply.agreement_confirm_time IS NULL
OR apply.agreement_confirm_time = ''
)
) THEN
'待协议确认'
ELSE
orderstatus.outer_biz_status_name
END
) AS externalStatusInfo,
(
CASE
WHEN (repayAcc.is_settle = 1) THEN (select actual_repayment_date from aim_t_loan_repay_process process
where process.assets_code= assets.assets_code and process.is_settle='1' ORDER BY cur_period desc limit 1)
END
) AS settledDate,
apply.apply_no
FROM
aim_t_loan_apply apply
LEFT JOIN aim_t_outer_inner_status orderstatus ON orderstatus.inner_biz_status_code = apply.apply_status
LEFT JOIN aim_t_cust_base cust ON apply.cust_code = cust.cust_code
LEFT JOIN aim_t_loan_assets assets ON apply.apply_no = assets.apply_no
LEFT JOIN aim_t_loan_repay_account_status repayAcc ON repayAcc.assets_code = assets.assets_code
LEFT JOIN aim_t_assets_platform platform ON apply.assets_platform_code = platform.platform_code
LEFT JOIN aim_t_product product ON apply.product_code = product.product_code
LEFT JOIN aim_t_product_sub subproduct on (product.product_code = subproduct.product_code and apply.loan_period = subproduct.period and subproduct.deleted = '0')
LEFT JOIN aim_t_cust_sub_account account ON (cust.id_no = account.id_no AND cust.id_type = account.id_type)
LEFT JOIN aim_t_risk_third_exception ex ON ex.apply_no = apply.apply_no
LEFT JOIN aim_t_loan_audit audit1 on (audit1.apply_no = apply.apply_no and audit1.result_type=3)
LEFT JOIN aim_t_loan_audit audit2 on (audit2.apply_no = apply.apply_no and audit2.result_type=4)
WHERE
apply.deleted = '0' ORDER BY apply.id limit 1000;
复杂的sql参考(3)的更多相关文章
- SQL 参考
本主题将介绍 ArcGIS 中的选择表达式所用的常规查询的各个元素.ArcGIS 中的查询表达式使用常规 SQL 语法. 警告: SQL 语法不适用于使用字段计算器计算字段. 字段 在 SQL 表达式 ...
- Hadoop-Impala学习笔记之SQL参考
参考:Apache Impala Guide--Impala SQL Language Reference. Impala使用和Hive一样的元数据存储,Impala可以访问使用原生Impala CR ...
- mybatis sql参考
参考mybatis sql: <select id="xxx" resultType="com.xxxx.xxx.vo.xx.xx" parameterT ...
- Linq to SQL 参考Demo
LINQ to SQL语句()之Where Where操作 适用场景:实现过滤,查询等功能. 说明:与SQL命令中的Where作用相似,都是起到范围限定也就是过滤作用的,而判断条件就是它后面所接的子句 ...
- Entity Framework关于SQL注入安全问题
1.EF生成的sql语句,用 parameter 进行传值,所以不会有sql注入问题 2.EF下有涉及外部输入参数传值的,禁止使用EF直接执行sql命令方式,使用实体 SQL 参考: https: ...
- PHP操作SQL Server 2008/2012
PHP操作SQL Server驱动,微软官方提供2个版本,Version 2.0 和 Version 3.0 Version 2.0 版本支持的操作系统有: Windows Server 2003 S ...
- SQL开发——SQL语法
文档资料参考: 参考:http://www.w3school.com.cn/sql/sql_syntax.asp 参考:http://wiki.jikexueyuan.com/project/sql/ ...
- SQL Server 日常维护经典应用
SQL Server日常维护常用的一些脚本整理. 1.sql server开启clr权限: GO RECONFIGURE GO ALTER DATABASE HWMESTC SET TRUSTWORT ...
- SQL 语法笔记
➪SQL ➪基本类型 char / varchar / int / smallint / numeric / real, double precision / float ➪数据定义 create t ...
随机推荐
- [转载] miller rabin
本文转载自https://www.cnblogs.com/zsq259/p/11602175.html Miller-Rabin 事先声明,因为菜鸡Hastin知识水平有限就是菜,因此语言可能不是特别 ...
- js-Cannot read property 'innerHTML' of null
原因:1.$('#xxx') 或$('.xxx')不存在 2.$('#xxx')或$('.xxx')的值为空
- vim文本编辑器——替换、保存退出
1.替换: (1)全文替换: 利用查询命令查询: (2)指定替换的字符串的范围: 2.保存.退出命令: (1)在命令行模式下保存(:w) (2)另存为(:w+要保存的文件的路径) (3)保存退出(:w ...
- micronaut 学习一 基本安装
一般来说,使用框架就是使用类库同时按照框架的类库套路编写代码,但是从越来越复杂的实际 场景来说,cli以及脚手架工具,可以帮助我们简化好多操作. 以下是micronaut cli 工具的安装以及一个简 ...
- A*G#C001
AGC001 A BBQ Easy 贪心. https://agc001.contest.atcoder.jp/submissions/7856034 B Mysterious Light 很nb这个 ...
- 【luoguP4720】【模板】扩展卢卡斯
快速阶乘与(扩展)卢卡斯定理 \(p\)为质数时 考虑 \(n!~mod~p\) 的性质 当\(n>>p\)时,不妨将\(n!\)中的因子\(p\)提出来 \(n!\) 可以写成 \(a* ...
- 安装和启动ElasticSearch服务遇到的几个问题
首先安装和启动服务的教程是参考文章:ES入门之一 安装ElasticSearch 然后在最后的启动es服务时遇到了几个小问题,因此在这里记录一下. 因为我对linux并不是很熟悉,因此文中如果有说错的 ...
- UDF——涡量
用涡量的模来显示涡结构是一种很常用的方法 涡量: 针对二维,涡量场表示为如下的标量: 对于二维流动来说,涡量为正,表示逆时针旋转:涡量为负,表示顺时针旋转 三维涡量: 其中: 计算涡量的模: 二维涡量 ...
- java复制对象之深拷背
在java开发中,有时我们需要复制对象,并且确保修改复制得到的对象不会影响原来的对象. 于是,有些人可能会写出类似以下的代码: public class CloneTest { public stat ...
- Apache Kylin - 大数据下的OLAP解决方案
OLAPCube是一种典型的多维数据分析技术,Cube本身可以认为是不同维度数据组成的dataset,一个OLAP Cube 可以拥有多个维度(Dimension),以及多个事实(Factor Mea ...