MySQL-搜索自定义列 [英] MySQL - Search into a custom Column
本文介绍了MySQL-搜索自定义列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想运行这样的MySQL查询-
I want to run a MySQL query like this-
SELECT country_ID*2/id*3.159 as my_id
FROM `state`
WHERE my_id>2;
当我运行它时,出现这样的错误-
When I run it, I am getting an error like this-
1054-"where子句"中的未知列"my_id"
1054 - Unknown column 'my_id' in 'where clause'
是否有其他解决方案可在我新创建的虚拟列 my_id 中进行搜索?
Is there any alternative solution to search in my new created virtual column my_id ?
实际上,我正在尝试在 Laravel查询生成器 这样-
Actually I am trying to make a search in Laravel Query Builder like this-
DB::table( 'project')->select( 'project.id as id',
'project.completion_date as completion_date',
DB::raw('FORMAT(project.total_cost_to_dispose - project.actual_cost_dispose, 2) as disposal_savings')
)
->where(disposal_savings>100);
我可以吗?
如果没有,那么Laravel或MySQL中的解决方案是什么?
If not, then what is the solution in Laravel or MySQL?
推荐答案
在where子句中再次使用完整条件,如下:
Use complete condition again in where clause as:
DB::table( 'project')->select( 'project.id as id',
'project.completion_date as completion_date',
DB::raw('FORMAT(project.total_cost_to_dispose - project.actual_cost_dispose, 2) as disposal_savings')
)
->where FORMAT(project.total_cost_to_dispose - project.actual_cost_dispose, 2) > 100;
这篇关于MySQL-搜索自定义列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文