php - mysql check row for same values and add together -
table structure image score breakdowni have table of golf scores called scores. column headings golfer, golf_course, h1, h2, h3 , on h18. have form adds scores in each column on basis of 0 = no score, 1 = bogey, 2 = par, 3 = birdie, 4 = eagle. trying achieve statement can return number of no scores, bogeys, pars, birdies or eagles each row. grateful for.
thanks subin c poonamgode,
you got me on right track. tweaked solution make following code work
select `golfer`,`course_name`, (case 0 when `h1` 1 else 0 end +case 0 when `h2` 1 else 0 end +case 0 when `h3` 1 else 0 end +case 0 when `h4` 1 else 0 end +case 0 when `h5` 1 else 0 end +case 0 when `h6` 1 else 0 end +case 0 when `h7` 1 else 0 end +case 0 when `h8` 1 else 0 end +case 0 when `h9` 1 else 0 end +case 0 when `h10` 1 else 0 end +case 0 when `h11` 1 else 0 end +case 0 when `h12` 1 else 0 end +case 0 when `h13` 1 else 0 end +case 0 when `h14` 1 else 0 end +case 0 when `h15` 1 else 0 end +case 0 when `h16` 1 else 0 end +case 0 when `h17` 1 else 0 end +case 0 when `h18` 1 else 0 end) blobby scores
to other condition need changed case 0 1, 2, 3 , 4. again :-)
Comments
Post a Comment