子查询结果sqlite不存在这样的列

问题描述 投票:0回答:1

我正在将 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
mysql node.js database sqlite node-sqlite3
1个回答
0
投票

您需要在选定的别名之间添加逗号

select firstname,
       lastname,
       (select cityname from table2 where id = 1) as city, -- <- here   
       (select city || "pink city")               as citywithcredit
from table1 

因为您需要单独选定的列,城市和带有信用的城市

© www.soinside.com 2019 - 2024. All rights reserved.