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 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="VE1 M" GROUP BY dni ORDER BY punts DESC, desempat ASC..
Pos Nom AmpollaPerellóCamarlesTortosaDeltebreJesús Total Punts
1 BALAGUE BELTRAN, JOAQUIN 93937911500 380 380
2 TORREBLANCA CERVELLÓ, JOSE ANGEL 0073103850 261 261
3 ORTEGA BLANCO, JAIME 085750790 239 239
4 GRUESO OTALO, ANTONIO 1151150000 230 230
5 EL JIHAOUI, AZZIZ 00115000 115 115
6 PALÀ RAMOS, ELOI 00001150 115 115
7 RIERA FLORES, JORDI 10300000 103 103
8 TORTOSA, DAVID 00103000 103 103
9 LEANDRO QUERO, JORDI 00001030 103 103
10 ALBACAR CLIMENT, CONRAD 01030000 103 103
11 GARCÍA ANTA , JESUS 0093000 93 93
12 FERRE FOLCH, DAVID 0000930 93 93
13 TORRES , JORGE 0085000 85 85
14 POQUET DOMENECH, PAU 8500000 85 85
15 FUSTER GIL, ANGEL LLUIS 0790000 79 79
16 LLORET PÉREZ, GASPAR 0000750 75 75
17 BRULL MARGALEF, JORDI 0750000 75 75
18 BARBERA MARTI, VICTOR MANUEL 0000730 73 73
19 SAMANIEGO GOMEZ, XAVI 0730000 73 73
20 MARTI MARTI, MARC SEBASTIA 0071000 71 71
21 ALBIAC VIÑOLAS, FERRAN 0710000 71 71
22 TERAN GOMEZ, JOAN 0070000 70 70
23 GONZÀLEZ CORTINA, OSCAR 0700000 70 70
24 OLLE CAMPAMA, FRANCESC 0069000 69 69