› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
xcc7624
V2EX  ›  MySQL

SQL 查询逾期还款问题

  •  
  •   xcc7624 · Dec 24, 2016 via Android · 4589 views
    This topic created in 3564 days ago, the information mentioned may be changed or developed.
    各位求指导
    现在我们把借款的还款计划设计在 Loan 表中,合同号 ID ,还款期次 term ,应还款日期 planpay ,实际还款日 actually ;现在现在希望当天首次出现逾期超过 30 天的合同号和逾期天数。如何处理
    3 replies  •  2017-02-14 10:07:17 +08:00
    oclock
        1
    oclock  
       Dec 24, 2016
    看起来 id 和(term, planpay, actually)有一对多关系

    select
    id, MAX(age(coalesce(actually, current_timestamp), planpay)) as overdue_days
    from
    load
    where
    actually is null or actually > planpay
    group by
    1

    PostgreSQL, noqa
    alexnone
        2
    alexnone  
       Jan 23, 2017
    当天首次出现逾期超过 30 天的合同号和逾期天数

    这句话有点不好理解 按我理解就是 31 天欸
    staticor
        3
    staticor  
       Feb 14, 2017
    1 将 id 先根据还款期次和首次应还款日期, 展开之后的 N 期还款日期;

    2 等额(本息)还款, 把实际还款日期和上面的应还日期取 diff, 得到逾期日期;

    3 考虑提前还款的问题;

    辅助函数 rank() datediff()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3631 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:54 · PVG 08:54 · LAX 17:54 · JFK 20:54
    ♥ Do have faith in what you're doing.