SELECT s.j_id, (select jockey from jockeys where j_id=s.j_id) as jockeyname, sum(s.first_status) as firstplace, sum(s.second_status) as secondplace, sum(s.third_status) as thirdplace, sum(s.fourth_status) as fourthplace, sum(s.fifth_status) as fifthplace, sum(s.sixth_status) as sixthplace, (sum(s.up)+sum(s.sixth_status)) as up, (sum(s.first_status) + sum(s.second_status)+ sum(s.third_status) + sum(s.fourth_status) + sum(s.fifth_status) + sum(s.sixth_status) + sum(s.up)) as totalrace, (sum(s.first_price) ) as totalFirst, (sum(s.second_price)+ sum(s.third_price) + sum(s.fourth_price) + sum(s.fifth_price) + sum(s.sixth_price)) as totalPlace, (sum(s.first_price)+sum(s.second_price)+ sum(s.third_price) + sum(s.fourth_price) + sum(s.fifth_price) + sum(s.sixth_price)) as totalWinnin FROM statistics s where s.status=1 and (SELECT race.Race_No FROM race Inner Join raceinput ON race.Race_AutoId = raceinput.Race_AutoID where raceinput.id =s.linesid and race.Race_No<>'') <>''and s.result_race<>'NR' and s.result_race<>'WD' and s.result<>'' and s.racedate >= and s.racedate <= GROUP BY (select jockey from jockeys where j_id=s.j_id) order by sum(s.first_status) desc, sum(s.second_status) desc, sum(s.third_status) desc, sum(s.fourth_status) desc, sum(s.fifth_status) desc, sum(s.sixth_status) desc, (sum(s.second_price)+ sum(s.third_price) + sum(s.fourth_price) + sum(s.fifth_price) + sum(s.sixth_price)) desc