VETERŔ-1 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 una, IFNULL((SELECT puntscat FROM historic5 WHERE idcursa=222 AND dni=doc ),0) AS dos, 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, IFNULL((SELECT puntscat FROM historic5 WHERE idcursa=227 AND dni=doc ),0) AS siet, IFNULL((SELECT puntscat FROM historic5 WHERE idcursa=228 AND dni=doc ),0) AS vuit, IFNULL((SELECT puntscat FROM historic5 WHERE idcursa=229 AND dni=doc ),0) AS nou, SUM(puntscat) AS punts, SUM(empat) as desempat FROM historic5 WHERE categoria="VE1 M" GROUP BY dni ORDER BY punts DESC, desempat ASC..
Pos Nom AmpostaAmpollaPerellóCamarlesTortosaJesúsDeltebreL'Aldea Total Punts
1 CAMPOY LOZANO, JUAN 103718500000 259 259
2 TORREBLANCA CERVELLÓ, JOSE ANGEL 791037500000 257 257
3 LUQUE LLUCH, OLIVER 93857000000 248 248
4 ORTEGA BLANCO, JAIME 75937300000 241 241
5 BALAGUE BELTRAN, JOAQUIN 71797100000 221 221
6 LLUCH ARBONA, FRANCESC 8507900000 164 164
7 FRANCH BONET, ROSANA 6669000000 66 135
8 CARMONA PARADA, FRANCESC 0011500000 115 115
9 RODRIGUEZ SUBIRATS, DAVID 1150000000 115 115
10 PAGA MARGALEF, JOAN PERE 0115000000 115 115
11 BENAIGES MARGALEF, JOSEP 0010300000 103 103
12 LEANDRO QUERO, JORDI 009300000 93 93
13 SOTO PAREDES, DANIEL 075000000 75 75
14 LLUIS LLANSAMA, ANTONIO 730000000 73 73
15 MARTINEZ DE LEON, ORIOL 073000000 73 73
16 VECIANA CARBONELL, JOSEP 700000000 70 70
17 GARBI HUERGA, CARLOS TOMÁS 070000000 70 70
18 SAMPER BRUNO, ALBERT 690000000 69 69
19 FANDOS COLOMINES, FELIP 006900000 69 69
20 GONZÁLEZ MARCOS, DANIEL 069000000 69 69
21 GARRIGA SANZ, ANTONI 680000000 68 68