TABLE(test)
a     b
1     1
1     1
2     2
2     2
2     2
3     3
select distinct a,b from test
出来
1    1
2    2
3    3
有没有办法,不用distinct ,而出来这样的结果,只有两个字段,a,b,请高手指点

解决方案 »

  1.   

    sql 2000得用临时表。sql 2005可参考如下:select a , b from
    (
      select * , px = row_number() over(partition by a , b order by a , b) from test
    ) t
    where px = 1
      

  2.   

    try~~~
    select a,b 
    from (select a,b ,count(1) c from test group by a,b) m
      

  3.   

    CREATE TABLE testp(a INT,b int)INSERT INTO testp
    SELECT 1, 1
    UNION ALL
    SELECT 1, 1
    UNION ALL
    SELECT 2, 2
    UNION ALL
    SELECT 2, 2
    UNION ALL
    SELECT 2, 2
    UNION ALL
    SELECT 3 ,3SELECT * FROM testp tselect a,b 
    from (select a,b ,count(1) c from testp group by a,b) ma           b
    ----------- -----------
    1           1
    2           2
    3           3(3 row(s) affected)
      

  4.   

    select  a,
            b 
    from test
    group by a,b
      

  5.   

    用group by 
    select a,b from test group by a,b
      

  6.   

    SELECT MAX(a),b FROM  t1 GROUP BY b