[英]getting a extra variable in mysql query
I am using Laravel and I am working on an existing project where I got a query我正在使用 Laravel 并且我正在处理一个我收到查询的现有项目
SELECT SUM(multi) as total
FROM ( SELECT men*hours as multi FROM report_task_manhours WHERE task_id=27013)X
Can anyone explain what is the use of X which is present in last in the query?任何人都可以解释查询中最后出现的X的用途是什么?
And it's working when I run this query in MySQL console.当我在 MySQL 控制台中运行此查询时,它正在工作。
X is working as an alias of your subquery which is below X 用作您的子查询的别名,如下所示
( select men*hours as multi from report_task_manhours where task_id=27013)
So if you want to use any of the other fields from your subquery to your main query then you need to use it with X.{field_name} as you can also use X.multi inside SUM function in your main query.因此,如果您想将子查询中的任何其他字段用于主查询,那么您需要将它与 X.{field_name} 一起使用,因为您还可以在主查询中的 SUM 函数中使用 X.multi 。
Like below像下面
select sum(X.multi) as total from ( select men*hours as multi from report_task_manhours where task_id=27013)X
I hope it's clear.我希望很清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.