如何及时从特定日期获取记录?

ss2ws0br  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(307)

编辑:15:09 2020-07-08,我解决了它,虽然它不是最佳解决方案或最整洁和苗条的解决方案,但它也能满足我的需要。所以感谢那些花时间评论和回答的人!
所以我有一个查询,我想输入一个日期,然后得到在那个日期“活动”的记录。我目前只使用当前日期,所以它是非常静态的。但如何使它更具动态性,这样我就可以像我说的那样选择任何一个时间,并获得数据?你有什么建议?
我正在pgadmin 4中使用postgresql9.6
如果这有什么帮助的话,现在请不要回答,但这是我的问题。。。。。

SELECT due.contract_id,due.component,due.due_not_paid, due.current_arrears_days,ob.outstandingamount, due.record_valid_to
FROM
    (SELECT a.record_valid_to, a.contract_id,a.component, sum(a.invoice_non_paid_waivedamount) as due_not_paid,max(no_latedays) as Current_arrears_days
    FROM
        (SELECT 
        sub.contract_id,sub.record_valid_to,sub.invoice_generation_date,sub.invoice_duedate,sub.invoice_paiddate,
        sub.invoice_dueamount,sub.invoice_paid_waivedamount,sub.invoice_non_paid_waivedamount,sub.component,
        CASE WHEN sub.invoice_dueamount = 0 THEN 0 ELSE sub.latedays END as no_latedays,
        CASE WHEN sub.invoice_non_paid_waivedamount > 0 AND invoice_duedate < current_date THEN 'DUE' ELSE 'PAID or non-due' END AS Paid_status
        FROM
            (select contract_id,record_valid_from,record_valid_to,invoice_generation_date,invoice_duedate,invoice_paiddate, invoice_dueamount,invoice_paid_waivedamount,
            CASE WHEN invoice_paid_waivedamount>0  AND (invoice_dueamount=invoice_paid_waivedamount) THEN (invoice_paiddate-invoice_duedate) ELSE (current_date-invoice_duedate) END as latedays,
            (invoice_dueamount-invoice_paid_waivedamount) as invoice_non_paid_waivedamount,component
            from dwd_tb_contracts_invoices where record_valid_to='9999-12-31' 
            ORDER BY invoice_duedate) 
         sub) a
    WHERE a.Paid_status = 'DUE'
    GROUP BY a.record_valid_to, a.contract_id, a.component) due
LEFT OUTER JOIN
    (select * from exposure_split('2020-07-06')) ob 
    ON due.contract_id = ob.contract_id
    where due.component = 'INTEREST_INTERMEDIATE'
or due.component = 'PRINCIPAL'
or due.component = 'INTEREST'
or due.component = 'INTEREST_DIFFERENCE'
    order by contract_id
rhfm7lfc

rhfm7lfc1#

如果您说的是插入时间,那么您可以创建一个函数过程,自动将当前日期和时间设置为该表的一个单元格,不允许直接访问它,然后直接查询它。如果要访问行或表,也可以这样做。
我不太喜欢sql,我也没有评论的代表,但如果你能写一个相同的代码,请让我知道…这样我就可以安全地删除答案然后。

相关问题