我已经提到过:
How to use alias as field in mysql
&
Adding MySQL alias fields together
我想对别名字段进行一些计算,但它会抛出错误
以下是我的查询
select j.*,
(select sum(stars) from ratingstar where jobid=j.id) as stars,
(select count(*) from ratingstar where jobid=j.id) as count,
((stars/(count*5)*5)) as rating //I have problem here if I remove this it works fine
from jobs j inner join proposals p on p.jobid=j.id
inner join us_signup u on u.id=p.userid
inner join hired h on h.proposalid=p.id
where h.status="finished"
但它抛出错误
此选择行出错
select j.*,
(select sum(stars) from ratingstar where jobid=j.id) as stars,
(select count(*) from ratingstar where jobid=j.id) as count,
((stars/(count*5)*5)) as rating //I have problem here if I remove this it works fine
错误是
Fatal error: Uncaught exception 'Exception' with message 'Unknown column 'stars' in 'field list' query: select j.,(select sum(stars) from ratingstar where jobid=j.id) as stars,(select count() from ratingstar where jobid=j.id) as count,((stars/(count*5)*5)) as rating from jobs j inner join proposals p on p.jobid=j.id inner join us_signup u on u.id=p.userid inner join hired h on h.proposalid=p.id where h.status="finished"' in E:\wamp\www\sugumar\mysuite\includes\classes\MysqliDb.php on line 3637
最佳答案
我想你最后错过了一个)
((stars/(count*5)*5))
编辑*你没有错过,只是在开头加了一个没用的
(stars/(count*5)*5)
关于mysql : calculations on alias fields in mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44501094/