SQL选择AS - 前置文本

时间:2014-11-01 14:31:43

标签: mysql sql

是否可以将文本添加到SQL select语句中。 e.g:

var query = "SELECT id, " +
                   "picture " 
            "FROM people";

var query = "SELECT id, " +
                   "picture AS './directory/' + picture "
            "FROM people";

2 个答案:

答案 0 :(得分:0)

是。像这样:

  var query = "SELECT id, " +
              "concat('./directory/',picture) AS  picture "
              "FROM people";

更多细节:http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat

答案 1 :(得分:0)

您正在将查询构造为字符串,所以是的,您可以这样做。但是,您必须将值作为常量插入。类似的东西:

var query = "SELECT id, " +
                   "picture AS " + directory " + "picture "
            "FROM people";

但是,directory需要是应用程序中的值而不是数据库(尽管另一个语句可以读取它)。