Skip to content
Advertisement

How to group data by year with paid and unpaid values

i have a MYSQL database where i want to sort the totals of both paind and unpaid amounts. The Query i used was :

i got the results as:

Where 1 stands for PAID and 0 stand for UNPAID

in my php code, i tried to group the data into years

This returns the output:

Where y is YEARS , a is PAID and b is UNPAID

What i seek to achieve is to group all the data to a particular year where i would have [{"y":"2017","a":"1995","b":0}, {"y":"2018","a":"1200","b":0}, {"y":"2019","a":"4990","b":"1450"}]

Without it duplicating the year but rather merging them into a single unit.

What do i need to do, and which code do i need to implement to achieve this.

Advertisement

Answer

Do you just want conditional aggregation?

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