查询出表TB中字段CL 中所有带有‘数’‘据’ 两个字的记录 必须 ‘数’ 在前 ‘据’在后
必须同时包含这两个字
如 ‘数据库开发’ 可以查出
    ‘数学知识’ 查不出
    ‘据数学家说’ 查不出
 如题 求SQL语句

解决方案 »

  1.   

    SELECT * FROM TB WHERE 
    (CL LIKE '%数%' OR CL LIKE '%据%' )
    AND CHARINDEX('数',CL)<CHARINDEX('据',CL)
      

  2.   

    有误要修改
    SELECT * FROM TB WHERE 
    (CL LIKE '%数%' OR CL LIKE '%据%' ) OR 
    (CL LIKE '%数%' AND CL LIKE '%据%'AND CHARINDEX('数',CL)<CHARINDEX('据',CL))
      

  3.   

    select *  from where cl like '%数据%' or cl like'%数%据'%
      

  4.   

    不知道sql里有没有matches
    where CL matches ‘×数×据×’
      

  5.   

    if object_id('tb')is not null drop table tb
    go
    create table tb(col nvarchar(10))
    insert tb select N'数据库开发'
    insert tb select N'数学知识'
    insert tb select N'据数学家说'
    select * 
    from tb
    where 
    charindex(N'数',col)>0 and charindex(N'据',col)>0
    and charindex(N'数',col)>charindex(N'据',col)
    /*
    col
    ----------
    据数学家说(1 個資料列受到影響)*/
    if object_id('tb')is not null drop table tb
    go
    create table tb(col nvarchar(10))
    insert tb select N'数据库开发'
    insert tb select N'数学知识'
    insert tb select N'据数学家说'
    select * 
    from tb
    where 
    charindex(N'数',col)>0 and charindex(N'据',col)>0
    and charindex(N'数',col)>charindex(N'据',col)
    /*
    col
    ----------
    据数学家说(1 個資料列受到影響)*/
      

  6.   

    --反了
    if object_id('tb')is not null drop table tb
    go
    create table tb(col nvarchar(10))
    insert tb select N'数据库开发'
    insert tb select N'数学知识'
    insert tb select N'据数学家说'
    select * 
    from tb
    where 
    charindex(N'数',col)>0 and charindex(N'据',col)>0
    and charindex(N'数',col)<charindex(N'据',col)
    /*
    col
    ----------
    数据库开发(1 個資料列受到影響)*/
      

  7.   

    select *  from 表a where cl like '%数据%' or cl like'%数%据'
      

  8.   

    必须同时包含这两个字晕要同时包含呀SELECT * FROM TB WHERE 
    (CL LIKE '%数%' AND CL LIKE '%据%'AND CHARINDEX('数',CL)<CHARINDEX('据',CL))
    那这样就行了
      

  9.   

    if object_id('tb')is not null drop table tb
    go
    create table tb(col nvarchar(10))
    insert tb select N'数据库开发'
    insert tb select N'数学知识'
    insert tb select N'据数学家说'
    insert tb select N'数学家根据一定理论'select * from tbselect * from tb where col like '%数%据%'/*
    数据库开发
    数学家根据一定理论
    */
      

  10.   

    if object_id('tb')is not null drop table tb
    go
    create table tb(col nvarchar(10))
    insert tb select N'数据库开发'
    insert tb select N'数学知识'
    insert tb select N'据说数据学说'select *  from TB  where COL like '%数据%' or COL like'%数%据'
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)col        
    ---------- 
    数据库开发
    据说数据学说(所影响的行数为 2 行)
    我上面的例子说错了,呵呵,是据要在数前面才是反例,楼主的不保险
      

  11.   

    if object_id('tb')is not null drop table tb
    go
    create table tb(col nvarchar(10))
    insert tb select N'数据库开发'
    insert tb select N'数学知识'
    insert tb select N'据数学家说'
    insert tb select N'数学家根据一定理论'
    insert tb select N'数据数'
    select * from tbselect * from tb where col like '%数%据%'/*
    数据库开发
    数学家根据一定理论
    数据数
    */7哥帮看看我这个有问题没?
      

  12.   

    如果有数据 ‘据说数学家据说’
    select * from tb where col like '%数%据%'
    会不会查出呢。。
      

  13.   

    晕,没考虑好,这样if object_id('tb')is not null drop table tb
    go
    create table tb(col nvarchar(10))
    insert tb select N'数据库开发'
    insert tb select N'数学知识'
    insert tb select N'说数据学说'select *  from TB  where  COL like'%数%据'
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)col        
    ---------- (所影响的行数为 0 行)
    也不行,楼上的那位也不行
      

  14.   

    SELECT * FROM TB WHERE 
    (CL LIKE '%数%' AND CL LIKE '%据%'AND CHARINDEX('数',CL)<CHARINDEX('据',CL))‘据说数学家据说’据会查出两个下标
     ‘数’会和哪个‘据’的哪个下标做比较 还是说都比较下 有小于的就成立
      

  15.   

    SELECT * FROM TB WHERE 
    (CL LIKE '%数%' AND CL LIKE '%据%'AND CHARINDEX('数',CL)<CHARINDEX('据',CL))‘据说数学家据说’据会查出两个下标
    ‘数’会和‘据’的哪个下标做比较 还是说都比较下 有小于的就成立
      

  16.   

    select * from tb where (col like '%数%' and col like '%据%' and charindex('数',col)<charindex('据',col))
    调试通过