aging report in mysql code example

Example: aging report in mysql

SELECT insuranceCode,    SUM(IF(DATEDIFF(CURDATE(), billedDate ) BETWEEN 1 AND 30, balanceAmount, 0)) AS age130,    SUM(IF(DATEDIFF(CURDATE(), billedDate ) BETWEEN 31 AND 60, balanceAmount, 0)) AS age3160,    SUM(IF(DATEDIFF(CURDATE(), billedDate ) BETWEEN 61 AND 90, balanceAmount, 0)) AS age6190,    SUM(IF(DATEDIFF(CURDATE(), billedDate ) > 90, balanceAmount, 0)) AS agegt90,    SUM(balanceAmount) AS totalBalanceFROM billing  billWHERE	bill.balanceAmount  > 0GROUP BY insuranceCode  ORDER BY totalBalance DESC

Tags:

Sql Example