Forum

Posted by Ankit, March 30, 2022, 9:12 p.m.

does the solution need to be exactly same as in solution tab?

I was solving a problem `Amazon employees' annual bonus` where I came up with the solution which is not exactly same as that in solution and it was not getting accepted. Is this solution not correct or the system isn't accepting that ?

SELECT employee_id
    , first_name
    , last_name
    , joined_date
    , salary
    , CASE WHEN joined_date > '2021-05-01' THEN 0
        WHEN joined_date < '2021-01-01' THEN 10000
        WHEN joined_date < '2021-05-01' AND joined_date > '2021-01-01' 
            THEN (Day FROM (joined_date::timestamp - '2021-05-01'::timestamp))/120*1000
        ELSE 0
        END as bonus
FROM amzn_employees

SOLUTION:

SELECT first_name, last_name, CASE WHEN joined_date >= '2021-05-01' THEN 0
                                  WHEN joined_date < '2021-01-01' THEN 10000
                                  ELSE ('2021-05-01' -  joined_date) * 1.0 / 120 * 10000 END AS bonus
FROM amzn_employees;

 

Answers

Hi Ankit, you can have your own solution but the results need to match exactly the expected results. In this case, I think you are very close, just need to convert the 

            THEN (Day FROM (joined_date::timestamp - '2021-05-01'::timestamp))/120*1000
To match the decimals.

 

 

SQLPad user avatar

Leon (949)

March 31, 2022, 1:19 p.m.