SELECT s.h_id, (select Horse from horses where h_id=s.h_id) as name,(select Grand_Sire from horses where h_id=s.h_id) as grandSire, (select Sire from horses where h_id=s.h_id) as sire, (select Dam from horses where h_id=s.h_id) as dam, (select o.owner from horses h, owners o where h.o_id = o.o_id and h.h_id = s.h_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) ) 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 s.result_race<>'NR' and s.result_race<>'WD' and s.result<>'' and s.racetype=1 and s.racedate >= and s.racedate <= GROUP BY s.h_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