multiple values in mysql variable

后端 未结 6 2025
渐次进展
渐次进展 2021-02-05 13:49

The following works as expected when there is a single value stored in a variable.

SET @a := \"20100630\";
SELECT * FROM wordbase WHERE verified = @a;
         


        
6条回答
  •  既然无缘
    2021-02-05 14:20

    There's good solution described here: https://stackoverflow.com/a/11957706/1523961

    So can use something like this:

    SET @a := '20100630,20100701';
    SELECT * FROM wordbase WHERE FIND_IN_SET(verified, @a);
    

    Also, if you're selecting the ids for @a from another table, you can come up with following:

    SET @a := (SELECT GROUP_CONCAT(id) FROM someTable where yourBooleanExpressionHere);
    SELECT * FROM wordbase WHERE FIND_IN_SET(verified, @a);
    

提交回复
热议问题