查询语句
A列 B列
1    1
1    2
1    3
2    1
2    2
3    3
3    4我想查询出以A,B列分组后对应的B列所有值大于2的A列值,即结果只有是3的查询语句

解决方案 »

  1.   

    如果只有两列
    select distinct a列 from tb where b列>2有多列也同上面一样 你只查a列
      

  2.   

    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([A] int,[B] int)
    insert [tb]
    select 1,1 union all
    select 1,2 union all
    select 1,3 union all
    select 2,1 union all
    select 2,2 union all
    select 3,3 union all
    select 3,4
    goselect * from tb t
    where not exists(select 1 from tb where a=t.a and b<=2)/**
    A           B
    ----------- -----------
    3           3
    3           4(2 行受影响)
    **/
      

  3.   

    select * from tb t
    where not exists(select 1 from tb where a=t.a and b<=2)
    请教兄台
    select 1 from tb where a=t.a and b<=2是什么意思
      

  4.   


    select 1 from tb where a=t.a and b<=2  表tb中符合a=t.a and b<=2的记录--select 1 from tb的意思你可以在查询分析器执行下看看