我需要使用"WHERE IN"进行MySQL查询.这是我的查询:
var myQuery = 'SELECT uid FROM ' +tableName+ ' where Gender IN (' + Info.Gender.join() + ')';
如果我打印Info.Gender
它将是['男性','女性'],作为一个字符串.但是当查询完成时,它说
SELECT uid FROM appUsers where Gender IN (Male, Female)
但应该是:
SELECT uid FROM appUsers where Gender IN ('Male', 'Female')
这意味着它不需要女性作为一个字符串.
有任何想法吗?
您应该使用查询转义(假设您正在使用node-mysql
):
var myQuery = 'SELECT uid FROM ?? where Gender IN (?)'; connection.query(myQuery, [ tableName, Info.Gender ], ...);