SQL Syntax Error, details: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and s.racedate <= GROUP BY s.t_id order by sum(s.first_status) desc, sum(s.sec' at line 1
SELECT s.j_id, (select trainer from trainers where t_id=s.t_id) as trainer, 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.racetype=1 and s.racedate >= and s.racedate <= GROUP BY s.t_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, (select trainer from trainers where t_id=s.t_id) asc