mysql - Comparing row values SQL -
i have @ table lists values current month , previous month weekpart being we(weekend) , wd(weekdays)
weekpart months avrgapps avrgoffers avrgdisbursements 201509 441 259 40 201508 432 235 40 wd 201508 2218 1591 334 wd 201509 2267 1156 346
i need compare wd , values months , return 1 in column if current month value higher previous month , 0 if equal or lower previous month's value result table
weekpart months avrgapps avrgoffers avrgdisbursements 201509 441 259 40 201508 432 235 40 wd 201508 2218 1591 334 wd 201509 2267 1156 346 201509 1 1 0 wd 201509 1 0 1
i guess looking this?
select concat(current.months, '-', previous.months) months, if(current.avrgapps > previous.avrgapps, 1, 0) avrgapps, if(current.avrgoffers > previous.avrgoffers, 1, 0) avrgoffers, if(current.avrgdisbursements > previous.avrgdisbursements, 1, 0) avrgdisbursements ( select * t months = @current := (select max(months) t) ) current join ( select * t months = (select max(months) t months < @current) ) previous on current.weekpart = previous.weekpart
this give month diff results. i'm not sure want "union" data table.
Comments
Post a Comment