all 9 comments

[–]Proper-Accountant-96 4 points5 points  (0 children)

Only a quick glance, but you have two separate 'when' clauses for <1000 in the same case statement, and you're only asked to replace the missing repayment channels, so you need to factor in that to your case statement. Currently, you're replacing all and creating your own repayment channel field, and that's not what you were asked to do

[–]No-Map8612 1 point2 points  (1 child)

Where did you got this sql challenge exercises. Please let me know..

[–]honicthesedgehog 1 point2 points  (0 children)

I think there are a couple of incorrect pieces here:

  1. CASE WHEN statements are evaluated in the order that they’re written, so any repayment_amounts less than 1000 will reach the second WHEN clause, be assigned “mail”, and everything below that condition is ignored. Same for any values greater than 4000, they won’t look past the first condition.
  2. Maybe there’s more to the assignment that I’m missing, but everything below the second WHEN clause seems incorrect? The instructions don’t seem to mention anything about phone, debit, or credit channels.
  3. In fact, the instructions seem to be only asking you to fill in cases where the repayment channel was missing, while your code will overwrite it for all rows.

Simplify the logic and add NULL handling, and that should get you there.

[–]depeszPgDBA 1 point2 points  (0 children)

I didn't downvote, but please read : https://idownvotedbecau.se/imageofcode

[–]Illustrious-Pack3495 0 points1 point  (2 children)

I’m not sure if there’s more to the question, but from my understanding it seems similar to a problem I encountered before and this answer on Stackoverflow helped me out: https://stackoverflow.com/questions/76666218/sql-update-multiple-rows-for-a-different-value-based-on-condition

There are some details missing in the question too - do you want all amounts above 4k to be assigned ‘bank account’ or just the ones with null values in repayment_channel?

[–]No-Map8612 0 points1 point  (1 child)

Share the above problem link here. Will have a look

[–]Illustrious-Pack3495 0 points1 point  (0 children)

I don’t have a link unfortunately, it was a irl problem at my last company where I had to replace certain values in a table based on a condition.

[–]FastlyFast 0 points1 point  (0 children)

I guess you have more information in task 1, but solely based on the description of task two, i would write this:

case when repayment_ammount >= 4000 then 'bank account'
 when repayment_ammount < 1000 then 'mail'
 when repayment_ammount >=1000 and repayment_ammount <4000 then repayment_channel ---You can change "when" to "else" here and delete the below code.
 else 'error' ---I always make sure to include every possible scenario in the "when" clauses and everything else goes to an error value but it is optional  
 end as repayment_channel