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)的更多相关文章

  1. SQL 参考

    本主题将介绍 ArcGIS 中的选择表达式所用的常规查询的各个元素.ArcGIS 中的查询表达式使用常规 SQL 语法. 警告: SQL 语法不适用于使用字段计算器计算字段. 字段 在 SQL 表达式 ...

  2. Hadoop-Impala学习笔记之SQL参考

    参考:Apache Impala Guide--Impala SQL Language Reference. Impala使用和Hive一样的元数据存储,Impala可以访问使用原生Impala CR ...

  3. mybatis sql参考

    参考mybatis sql: <select id="xxx" resultType="com.xxxx.xxx.vo.xx.xx" parameterT ...

  4. Linq to SQL 参考Demo

    LINQ to SQL语句()之Where Where操作 适用场景:实现过滤,查询等功能. 说明:与SQL命令中的Where作用相似,都是起到范围限定也就是过滤作用的,而判断条件就是它后面所接的子句 ...

  5. Entity Framework关于SQL注入安全问题

    1.EF生成的sql语句,用 parameter 进行传值,所以不会有sql注入问题 2.EF下有涉及外部输入参数传值的,禁止使用EF直接执行sql命令方式,使用实体 SQL   参考: https: ...

  6. PHP操作SQL Server 2008/2012

    PHP操作SQL Server驱动,微软官方提供2个版本,Version 2.0 和 Version 3.0 Version 2.0 版本支持的操作系统有: Windows Server 2003 S ...

  7. SQL开发——SQL语法

    文档资料参考: 参考:http://www.w3school.com.cn/sql/sql_syntax.asp 参考:http://wiki.jikexueyuan.com/project/sql/ ...

  8. SQL Server 日常维护经典应用

    SQL Server日常维护常用的一些脚本整理. 1.sql server开启clr权限: GO RECONFIGURE GO ALTER DATABASE HWMESTC SET TRUSTWORT ...

  9. SQL 语法笔记

    ➪SQL ➪基本类型 char / varchar / int / smallint / numeric / real, double precision / float ➪数据定义 create t ...

随机推荐

  1. 67-Flutter中高德地图插件的使用

    1.注册和建立高德API应用 高德网站:https://lbs.amap.com/ 控制台-应用管理-创建应用 在创建 Key 2.获得SHA1 进入Flutter项目中的android文件夹内,打开 ...

  2. PostgreSQL 慢查询SQL跟踪

    PostgreSQL 开启慢SQL捕获在排查问题时是个很有效的手段.根据慢SQL让我在工作中真正解决了实际问题,很有帮助. PostgreSQL 日志支持的输出格式有 stderr(默认).csvlo ...

  3. moco搭建json api网站用于接口测试

    java -jar moco-runner-1.0.0-standalone.jar http -p 12306 -c config/conf.json 配置文件 [ { "request& ...

  4. python函数 | 三元运算

    三元运算符就是在赋值变量的时候,可以直接加判断,然后赋值 格式: [on_true] if [expression] else [on_false] 三元运算只适用于简单的if else判断,再多一层 ...

  5. Python错误 -- try/except/finally 、调用栈、记录错误、抛出错误

    Bug:程序编写有问题造成的错误,称之为Bug.    debug:调试 注意:bug是程序本身有问题.有缺陷.系统漏洞 异常:完全无法在程序运行中预测的错误,例如写入文件的时候,磁盘满了,写不进去了 ...

  6. json-server模拟服务器API

    一.npm安装 npm install --global json-server 二.使用:创建一个json数据文件,比如: { "students": [{ "id&q ...

  7. P1501 [国家集训队]Tree II LCT

    链接 luogu 思路 简单题 代码 #include <bits/stdc++.h> #define ls c[x][0] #define rs c[x][1] using namesp ...

  8. SQL进阶-去重

    一.去重的2种基本方法 1.DISTINCT ## 建表: CREATE TABLE teacher( teacher_id ), teacher_name ), id_no ) ); CREATE ...

  9. 我用AI(Adobe Illustrator CS6)合并路径的两个常用方法

    作为一个切图仔,经常与设计大佬的PSD打交道,PSD里面又有各种icon图标需要导出,偷懒的方法直接导出png图片,丢个背景图上页面完美解决问题!! 第二天来个需求,能不能把这个icon图标给我换个颜 ...

  10. Android Studio软件技术基础 —Android项目描述---1-类的概念-android studio 组件属性-+标志-Android Studio 连接真机不识别其他途径

    学习android对我来说,就是兴趣,所以我以自己的兴趣写出的文章,希望各位多多支持!多多点赞,评论讨论加关注. 最近有点忙碌,对于我来说,学习Android开发,是对于我的考验,最近一位大佬发给我一 ...