php - Sum the value in if/else mysql select statement -
not sure how max date inside if/else statement of mysql query.
here select statement:
select month(max(a.planned_date)) month, a.planned_date date, year(max(a.planned_date)) year, sum(if(month(a.planned_date) = 1, b.value, 0)) jan, sum(if(month(a.planned_date) = 2, b.value, 0)) feb, sum(b.value) total b inner join on b.id = a.id inner join c on b.reg_id = c.reg_id year(a.planned_date) < date(now()) group c.reg_id
all trying have cross table of jan dec, return max date bring value. however, way have done value doubling value.
please advise appreciated.
thank you
Comments
Post a Comment