SELECT COUNT(d.hn) AS total,
IF(d.death_diag_4 <> " ",d.death_diag_4,
IF(d.death_diag_3 <> " ",d.death_diag_3,
IF(d.death_diag_2 <> " ",d.death_diag_2,
IF(d.death_diag_1 <> " ",d.death_diag_1,NULL)))) AS dx
FROM death d WHERE d.death_date BETWEEN '2013-01-01' AND '2014-01-31'
GROUP BY dx
ORDER BY total DESC LIMIT 20
ช่วยดูหน่อยครับ ไม่รู้ว่าโค๊ดนี้ใช้ได้เปล่า