I have a fairly complex case
statement that works in MySQL:
SELECT # rest of code omitted
CASE WHEN code = 'a' THEN 'x'
WHEN code IN ('m', 'n') THEN 'y'
WHEN class IN ('p', 'q') AND amount < 0 THEN 'z'
ELSE NULL END AS status
FROM # rest of code omitted
However, all attempts to write this in Sequel have failed. I am using this as a template:
Sequel.case([[:c, 1], [:d, 2]], 0) # (CASE WHEN "c" THEN 1 WHEN "d" THEN 2 ELSE 0 END)
(from Jeremy Evans' Github)
My best guess would be:
dataset.select( # rest of code omitted...
[[(:code => 'a'), 'x'],
[(:code => 'b'), 'y'],
[(:class => ['p', 'q'], :amount < 0), 'z']].case(nil).as(:status))
Any ideas?