By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
9 rows affected
ERROR: function last_day(date) does not exist
LINE 7: THEN ((s.fix_costs/ DAY(LAST_DAY(sales_date))) ...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.