复杂的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 ...
随机推荐
- C# VS常用操作
VS点击项目,就会打开文件,其实我只是想选中而已, 在这个地方可以改. 原文:https://blog.csdn.net/yellowegg/article/details/12217309
- luoguP4112 [HEOI2015]最短不公共子串 SAM,序列自动机,广搜BFS
luoguP4112 [HEOI2015]最短不公共子串 链接 luogu loj 思路 子串可以用后缀自动机,子序列可以用序列自动机. 序列自动机是啥,就是能访问到所有子序列的自动机. 每个点记录下 ...
- Macbook Pro 键盘触摸板失灵,只有电源键有反应 修复手札
上次说到换完电池后键盘和触摸板就没反应了,只好硬着头皮把所有的元件一个个拆下来试. 经过3天的测试(试了网上所有能找到的办法,最多的就是重置smc和nvmp),最终确定故障应该在触摸板排线上. 没有废 ...
- 第02组 Alpha冲刺(4/4)
队名:十一个憨批 组长博客 作业博客 组长黄智 过去两天完成的任务:了解整个游戏的流程 GitHub签入记录 接下来的计划:继续完成游戏 还剩下哪些任务:完成游戏 燃尽图 遇到的困难:没有美术比较好的 ...
- Powershell基础学习
从吐司偷来的图片,拿来当做引导吧: 0x01 简介 Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能.当然 ...
- 如何保证MQ的顺序性?比如Kafka
三.如何保证消息的顺序性 1. rabbitmq 拆分多个queue,每个queue一个consumer,就是多一些queue而已,确实是麻烦点:或者就一个queue但是对应一个consumer,然后 ...
- [Gamma阶段]第九次Scrum Meeting
Scrum Meeting博客目录 [Gamma阶段]第九次Scrum Meeting 基本信息 名称 时间 地点 时长 第九次Scrum Meeting 19/06/05 大运村寝室6楼 20min ...
- template cannot be keyed. Place the key on real elements instead.
template cannot be keyed. Place the key on real elements instead. 一.总结 一句话总结: 原因:vue不支持在 template 元素 ...
- 屏幕方向读取与锁定:Screen Orientation API(转)
什么是 Screen Orientation API Screen Orientation API 为 Web 应用提供了读取设备当前屏幕方向.旋转角度.锁定旋转方向.获取方向改变事件的能力.使得特定 ...
- Parquet介绍及简单使用(转)
==> 什么是parquet Parquet 是列式存储的一种文件类型 ==> 官网描述: Apache Parquet is a columnar storage f ...