复杂的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 ...
随机推荐
- Subband Decomposition
子带分解. 例如语音信号是宽带信号,根据奈奎斯特采样定理,采样率为16kHz的语音信号的有效带宽是8KHz,不论是对于降噪,aec,vad,波束形成亦或是logfbank特征提取,我们都期望更精细的处 ...
- UFUN函数 UF_CURVE函数(UF_CURVE_create_line、UF_CURVE_create_arc、UF_CURVE_ask_arc_data、UF_CURVE_ask_line_data)
UF_initialize(); //CSYS_ask_wcs tag_t wcs_id=NULL_TAG; //CSYS_ask_csys_info ]={0.0}; //CURVE_create_ ...
- 5-微信小程序开发(小程序页面跳转和布局说明)
https://www.cnblogs.com/yangfengwu/p/11605209.html 新建一个小程序 咱现在新建个页面 在pages 上右击,选择新建目录 会自动添加这几个文件 现在做 ...
- C++中list的用法总结
list简介 list 也是顺序容器的一种.只是list 是一个双向链表.使用 list 需要包含头文件 list.双向链表的每个元素中都有一个指针指向后一个元素,也有一个指针指向前一个元素,如下图所 ...
- word2vector的tensorflow代码实现
import collections import math import os import random import zipfile import numpy as np import urll ...
- 在CentOS上使用Docker镜像安装Jenkins
1.必须先在CentOS上安装Docker,使用以下命名先在Docker Hub上搜索Jenkins镜像 docker search jenkins 2.下载Jenkins镜像,命令如下:(我下载的是 ...
- arthas安装进docker
教程参照https://alibaba.github.io/arthas/arthas-tutorials mkdir /opt/downloads -pmkdir /opt/arthas -p下载地 ...
- jsch channel is not opened原因及解决
潜在原因1:服务器sshd限制,可通过如下解决: 潜在原因2:服务器负载过高,超时.在连接处增加超时时间session.setTimeout(60000);默认情况下,socket的超时时间大约为21 ...
- 虚拟机ubuntu16下cheese打开摄像头黑屏问题
在win7上安装了一个ubuntu1604的虚拟机: 在虚拟机下打开电脑上连接的摄像头时,用ubuntu16自带的cheese软件查看是黑屏: 但是cheese上有摄像头名字显示,就是打不开:如下图 ...
- 我的Mac上有哪些软件
工具 Pycharm CE GoLand Chrome 微信 网易云音乐 有道云笔记 iTerm Postman Sublime Text bashrc配置(支持显示git branch以及详细路径信 ...