简体   繁体   English

SQL select AS-前置文本

[英]SQL select AS - prepending text

Is it possible to prepend text to an SQL select statement. 是否可以在SQL选择语句前添加文本。 eg: 例如:

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

to

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

Yes. 是。 Something like this: 像这样:

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

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

You are constructing the query as a string, so yes, you can do this. 您正在将查询构造为字符串,所以可以。 However, you have to insert the value as a constant. 但是,您必须将值插入为常量。 Something like: 就像是:

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

However, directory would need to be a value in the application and not the database (although another statement could read it). 但是, directory需要是应用程序中的值,而不是数据库中的值(尽管其他语句可以读取它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM