Sql 如何在select语句中将列别名添加到子查询?
我试图在select语句中使用子查询的位置运行查询。Sql 如何在select语句中将列别名添加到子查询?,sql,oracle,select,alias,Sql,Oracle,Select,Alias,我试图在select语句中使用子查询的位置运行查询。 这项工作: select (select sysdate from dual), (select 'municipality' from dual), (select count(*) from municipality) from dual; 但是得到的列名很难看,因此我想添加列别名 我正在尝试运行以下查询: select (select sysdate from dual) as sysdate, (
这项工作:
select
(select sysdate from dual),
(select 'municipality' from dual),
(select count(*) from municipality)
from dual;
但是得到的列名很难看,因此我想添加列别名
我正在尝试运行以下查询:
select
(select sysdate from dual) as sysdate,
(select 'municipality' from dual) as tablename,
(select count(*) from municipality) as count
from dual;
此操作失败,ORA 00923:From关键字未找到,出现预期错误。
不知怎的,我错过了一些东西
有什么建议吗
谢谢。试着用双引号括起来
select
(select sysdate from dual) as "sysdate",
(select 'municipality' from dual) as "tablename",
(select count(*) from municipality) as "count"
from dual;
SysDate
是保留关键字。虽然,COUNT
是一个聚合函数,但允许使用它
select
(select sysdate from dual) s_date, -- NOT sysdate
(select 'municipality' from dual) tablename,
(select count(*) from dual) as cnt -- NOT count
from dual;
使用count是可以的,但在现实世界中这是不可取的,pro-s也不会使用关键字。生活可以如此简单。当然我得用引号。谢谢你的快速回答你的起始代码只是一个例子,对吗?如果这是真的,请使用
选择sysdate,'unicity'作为表名,count(*)作为countfrom unicity
。例子