VETERÀ-2 MASCULÍ

SELECT nom as sujeto, dni as doc, sexe as sex1, categoria as cate, IFNULL((SELECT puntscat FROM historic5 WHERE idcursa=221 AND dni=doc ),0) AS dos, IFNULL((SELECT puntscat FROM historic5 WHERE idcursa=222 AND dni=doc ),0) AS una, IFNULL((SELECT puntscat FROM historic5 WHERE idcursa=223 AND dni=doc ),0) AS tres, IFNULL((SELECT puntscat FROM historic5 WHERE idcursa=224 AND dni=doc ),0) AS quatre, IFNULL((SELECT puntscat FROM historic5 WHERE idcursa=225 AND dni=doc ),0) AS cinc, IFNULL((SELECT puntscat FROM historic5 WHERE idcursa=226 AND dni=doc ),0) AS sis, SUM(puntscat) AS punts, SUM(empat) as desempat FROM historic5 WHERE categoria="VE2 M" GROUP BY dni ORDER BY punts DESC, desempat ASC..
Pos Nom AmpollaPerellóCamarlesTortosaDeltebreJesús Total Punts
1 SANAHUJA BARRANCO, JOSEP RAMON 11511501151150 460 460
2 GARCIA REDONDO, DOMINGO 10310301031030 412 412
3 BERTOMEU BAILE, DAVID 001150930 208 208
4 ALONSO QUESADA, OSCAR 00093850 178 178
5 MARTINEZ BONET, JUAN ENRIQUE 00103000 103 103
6 MENENEDEZ GIMENO, ALEX 9300000 93 93
7 WATSON, JAMIE 8500000 85 85
8 JIMÉNEZ MUR, PERE JOSEP 0008500 85 85
9 CASANOVA CURTO, ALVAR 0000790 79 79