SUB-23 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="S23 M" GROUP BY dni ORDER BY punts DESC, desempat ASC..
Pos Nom AmpollaPerellóCamarlesTortosaDeltebreJesús Total Punts
1 ALDAO MORELLÓ, ERIC 0115011500 230 230
2 NAVARRO FALCÓ, JOSEP 09393000 186 186
3 ELAKRAA, OTHMAN 00115000 115 115
4 MORA SANSALONO, DAVID 00001150 115 115
5 SUBIRATS MARTÍN, JULIÀ 11500000 115 115
6 CRESPO PEREZ, DIDAC 00103000 103 103
7 VENTURA VENTURA, HÈCTOR 00001030 103 103
8 GARRIDO LOPEZ, MARCOS 01030000 103 103