[英]How to use aliases in mysql functions
How do i use aliases with spaces in mathematical functions and group by statements. 如何在数学函数中使用带空格的别名并按语句分组。 I am able to use it if I use single word aliases, but is there any way of achieving it if the name has spaces ?
如果我使用单字别名,则可以使用它,但是如果名称包含空格,有什么方法可以实现?
select
count(date_format(start_date, '%W')) AS "NUMBER OF DAYS",
repeat('*', "NUMBER OF DAYS")
from ABC
I tried using double-quotes,singe-quotes and also backticks(`), but it gives an error saying "Unknown column "NUMBER OF DAYS" in field list" 我尝试使用双引号,单引号和反引号(`),但是它给出了一个错误,提示“字段列表中的未知列“ NUMBER OF DAYS””
You can't reuse an alias in the select
or where
clause. 您不能在
select
或where
子句中重复使用别名。 Only in group
, having
, order
clauses. 仅在
group
, having
, order
子句。
You can use Derived table 您可以使用派生表
select
`NUMBER OF DAYS`,
repeat('*', `NUMBER OF DAYS`)
from
(
select
count(date_format(start_date, '%W')) AS `NUMBER OF DAYS`
from ABC
) as t
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.