SELECT s.o_id, (select owner from owners where o_id=s.o_id) as owner, 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))/3.68) as totalFirst, ((sum(s.second_price)+ sum(s.third_price) + sum(s.fourth_price) + sum(s.fifth_price) + sum(s.sixth_price))/3.68) 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))/3.68) 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<>'' and s.pamount = 'DOLLAR' and s.racedate >= and s.racedate <= GROUP BY (select owner from owners where o_id=s.o_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