Query Oracle SQL for rent on date

Asked 2 years ago, Updated 2 years ago, 50 views

Hello, I'm a beginner developer.

I want to think of it like this.

I don't know how to calculate it, so I'm asking you this question.

oracle sql java

2022-09-21 10:15

1 Answers

Date + Rent = Payment amount

It's not date * rental fee = payment amount right?

SELECT
    (TO_DATE('2020-04-01 10:05', 'YYYY-MM-DD HH24:MI')
            - - TO_DATE('2020-03-27 21:35', 'YYYY-MM-DD HH24:MI'))
            * Rent + Insurance Premium
FROM MY_TABLE

You can do it this way, but the problem is calculating the date. Just looking at the example above, the date doesn't exactly match, so the value 4.5208333333333333333333 comes out. If you're not going to set the rent on an hourly basis, you have to decide whether to throw away or raise the decimal point, but this depends on the policy, so think about it.

-- Date format omitted
SELECT 
    -- Five days
    TO_DATE('2020-04-01 10:05:00') - TO_DATE('2020-03-27 10:05:00'),
    -- 4.5208333333 days
    TO_DATE('2020-04-01 10:05:00') - TO_DATE('2020-03-27 21:35:00'),
    -- 5.4166666666 days
    TO_DATE('2020-04-01 20:00:00') - TO_DATE('2020-03-27 10:00:00')
FROM DUAL

If you set a standard time and exceed that time, the rental date is +1... There could be a policy like this.


2022-09-21 10:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.