SELECT username FROM `info` WHERE id
in ('919953990950_1403180247868.707,
919953990950_1403239797121.525,
919953990950_1403241821083.838,
919953990950_1403248486971.661,
919953990950_1403248511255.484,
919953990950_1403248860947.79,
919953990950_1403255594277.013') and username !='1403176452487620892' limit 50
这不是在我的查询中选择行有什么问题吗?
答案 0 :(得分:1)
您需要将每个值括在单引号中,而不是整个列表中:
SELECT username
FROM `info`
WHERE id in ('919953990950_1403180247868.707',
'919953990950_1403239797121.525',
'919953990950_1403241821083.838',
'919953990950_1403248486971.661',
'919953990950_1403248511255.484',
'919953990950_1403248860947.79',
'919953990950_1403255594277.013'
) and
username <> '1403176452487620892'
limit 50;
答案 1 :(得分:1)
通过将每个值放在quotes ''
中来尝试此操作,否则它会将整个视为一个字符串,并将!=
替换为<>
:
SELECT username
FROM `info`
WHERE id
in ('919953990950_1403180247868.707',
'919953990950_1403239797121.525',
'919953990950_1403241821083.838',
'919953990950_1403248486971.661',
'919953990950_1403248511255.484',
'919953990950_1403248860947.79',
'919953990950_1403255594277.013') and username <>'1403176452487620892'
答案 2 :(得分:1)
OP的评论:
我用scala语言插入字符串
当值设置为逗号分隔值
时,请使用find_in_set
SELECT username FROM `info`
WHERE FIND_IN_SET( id, csv_values )
AND username !='1403176452487620892' limit 50;
在上面的示例中,使用从 SCALA 收到的值字符串替换'csv_values'
我建议你使用Prepared Statement来绑定值。
请参阅: