Skip to content
Advertisement

Fields as result set headers in mysql 8

Below is the snippet of my data,

empid would be employee id and there are other employee id’s in the dataset but all will have similar data.

My aim to to show the various pay categories as columns in the query result like,

I am using the below query,

The deduction category are showing value as zero which should not be,

dbfiddle

Advertisement

Answer

There are columns whose values are negative, so the conditionl MAX() returns 0, because of the ELSE 0 branch of the CASE statement.

You can turn these to MIN()s:

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