我正在将 mysql 查询转换为 sqlite 查询,并且在 sqlite 查询中进一步使用 别名 时遇到问题,如下所述,
我有如下两张桌子,
table1 -> (id, firstname, lastname)
table2 -> (id, cityname)
我想执行子查询例如
select
firstname, lastname,
(select
cityname
from
table2
where
id=1
) as city <<<<<===== city alias works fine
from
table1
结果是,
firstname lastname city
问题是当我想在查询中进一步利用
city alias
时。
例如。对于城市别名结果,我想附加“粉红城市”
select
firstname, lastname,
(select
cityname
from
table2
where
id=1
) as city <<<<<===== city alias works fine
( select city || "pink city" ) as citywithcredit <<==== here it says city column doesn't exist (In Mysql same query works without problem)
from
table1
您需要在选定的别名之间添加逗号
select firstname,
lastname,
(select cityname from table2 where id = 1) as city, -- <- here
(select city || "pink city") as citywithcredit
from table1
因为您需要单独选定的列,城市和带有信用的城市