Skip to content
Advertisement

mysql 8 pivot query should return a non null value

I would like the following pivot query to show value 0 instead of null,

Output for the above is,

Employee id 122 does not have a Repayment value so the desired output is,

dbfiddle

Advertisement

Answer

I don’t see the need for the second branch of the repayment case. If you want 0 when the category is not available, just else 0:

Notes:

  • Don’t use single quotes for identifiers! They should be used for literal strings only, as specified in ANSI SQL and supported in all databases.

  • You have a mono-table query, so prefixing all column names is not mandatory

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement