代码之家  ›  专栏  ›  技术社区  ›  Sami

包含保留字的concat列[重复]

  •  1
  • Sami  · 技术社区  · 13 年前
    select concat(Sno,Table) as STB from levels
    

    如果按原样运行,上面的查询会出现错误。假设我在级别中有价值

    Sno   Table
    1     Sale
    2     Stock
    

    我需要把它们当作

    STB
    ---
    1Sale
    2Stock
    

    解决方案是什么 other than changing the column name 因为在单词周围加引号 'Table' 给出错误的输出,因为它变成了一个字符串

    3 回复  |  直到 13 年前
        1
  •  2
  •   James Cronen    13 年前

    保留字使用反勾号。

    select concat(Sno, `Table`) as STB from levels
    

    尽管一般来说,如果将来可以避免在数据库、表或列名中使用保留字,这是个好主意。

        2
  •  2
  •   D'Arcy Rittich    13 年前
    select concat(Sno,`Table`) as STB 
    from levels 
    
        3
  •  1
  •   Fry_95    13 年前

    尝试使用“代替”,如下所示:

    SELECT CONCAT(Sno,`Table`) AS STB FROM levels