【问题标题】:WHERE clause with strpos带有 strpos 的 WHERE 子句
【发布时间】:2015-09-08 06:29:51
【问题描述】:
create table test(variable varchar(20), col001 real, col002 real);
insert into test values('col001',1,2);
insert into test values('col002'3,4);

现在,我想查询这个以获得一个子矩阵

 select variable, col001, col002
 from test
 where strpos("col001,col002", variable) > 0

为什么这不起作用?

【问题讨论】:

  • "col001,col002" 是一个分隔标识符,即 dbms 认为它​​是一个列名。对字符串文字使用单引号。
  • @jarlh:请添加为回复,以便我接受。
  • 您使用的是哪个 DBMS?

标签: sql select


【解决方案1】:

"col001,col002" 是一个分隔标识符,即 dbms 认为它​​是一个列名。对字符串文字使用单引号。

select variable, col001, col002
from test
where strpos('col001,col002', variable) > 0

【讨论】:

    【解决方案2】:

    没有STRPOS是MsSQL:
    参考:SQL Server: any equivalent of strpos()?
    您可以在 MsSQL 中编写这样的查询:

    SELECT variable, col001, col002
    FROM test
    WHERE CHARINDEX('col001,col002', variable) > 0
    

    【讨论】:

    • 什么告诉你 OP 正在使用 SQL Server?
    猜你喜欢
    • 2011-07-23
    • 2011-08-02
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-21
    相关资源
    最近更新 更多