表A 中有一列B B列是用户名,里面有含英文的,有0开头的,有1开头的,这三种,现想用语句查询者三种,该怎么写?含英文的:select * from A where ***0开头的:select * from A where ***1开头的:select * from A where ***

解决方案 »

  1.   

    WHERE B LIKE '[0,1,a-zA-Z]%'
      

  2.   

    select * from A where left(f,1)='0'select * from A where left(f,1)='1'剩下的就是英文了
      

  3.   


    use tempdb;
    /*
    create table A
    (
    B nvarchar(10) not null
    );
    insert into A values('CDE'),('0AB'),('1CD');
    */
    select A.B as [字母开头] from A
    except
    (
    select A.B as [0开头] from A where A.B like '0%'
    union
    select A.B as [1开头] from A where A.B like '1%'
    );
    select A.B as [0开头] from A where A.B like '0%';
    select A.B as [1开头] from A where A.B like '1%';
      

  4.   


    declare @t table (col varchar(8))
    insert into @t
    select '09234234' union all
    select '13245255' union all
    select '0234234a' union all
    select '1gfsss45' union all
    select '2sdfsfsf' union all
    select '43645764'select * from @t where left(col,1)='0'
    /*
    col
    --------
    09234234
    0234234a
    */
    select * from @t where left(col,1)='1'
    /*
    col
    --------
    13245255
    1gfsss45
    */
    select * from @t where patindex('%[a-z]%',col) > 0
    /*
    col
    --------
    0234234a
    1gfsss45
    2sdfsfsf
    */
      

  5.   

    select * from #a where B like '1%'
    select * from #a where b like '0%'
    select * from #a where b like '%[A-Z]%'