如果表中我定义了一个username字段,然后我有一个字符串
strname=张三,李四,王五,
我想把username=张三,username=王五,username=李四的记录全查出来,怎么查啊?初学SQL,麻烦赐教咯:)

解决方案 »

  1.   

    declare @strname varchar(100)
    set @strname='张三,李四,王五'
    select * from [Table] where charindex(','+username+',',','+@strname+',')>0
      

  2.   

    select * from [table] where username in (张三,李四,王五)
      

  3.   


    我试了你写的这个,现在总抛错:check the manual that corresponds to your mysql server version for the right syntax to use near(','+ CategoryTree+ ',',','+categorytree+',')>0 这又是为啥呢?
      

  4.   

    你的是mysql吧?
    SELECT * FROM `Table` WHERE INSTR(',张三,李四,王五,',CONCAT(',',username,','))>0
      

  5.   

    又是一个在SQL SERVER问MYSQL的 直接select * from table1 where find_in_set(usname,'张三,李四,王五')就行了。