Sql ows,OP还没有澄清它是否可以接受。这对我来说确实是个问题。(另请参阅我对HakonB帖子的评论)我不能这样做,因为excel文件将包含客户数据。列A可能是重复的,但其余数据需要有序。如果我不需要它,这将是一个很好的解决方案。我想我确实会在客户端(如SQ

Sql ows,OP还没有澄清它是否可以接受。这对我来说确实是个问题。(另请参阅我对HakonB帖子的评论)我不能这样做,因为excel文件将包含客户数据。列A可能是重复的,但其余数据需要有序。如果我不需要它,这将是一个很好的解决方案。我想我确实会在客户端(如SQ,sql,excel,odbc,Sql,Excel,Odbc,ows,OP还没有澄清它是否可以接受。这对我来说确实是个问题。(另请参阅我对HakonB帖子的评论)我不能这样做,因为excel文件将包含客户数据。列A可能是重复的,但其余数据需要有序。如果我不需要它,这将是一个很好的解决方案。我想我确实会在客户端(如SQL server的客户端)执行此操作,这是最快的解决方案。可能有多达20列,使用所有这些子查询将导致系统运行非常缓慢。我应该使用orderby,并对照前面的结果进行检查。非常感谢。不是所有20列都用来决定选择哪一行,对吗?所以,在选择版本之前,


ows,OP还没有澄清它是否可以接受。这对我来说确实是个问题。(另请参阅我对HakonB帖子的评论)我不能这样做,因为excel文件将包含客户数据。列A可能是重复的,但其余数据需要有序。如果我不需要它,这将是一个很好的解决方案。我想我确实会在客户端(如SQL server的客户端)执行此操作,这是最快的解决方案。可能有多达20列,使用所有这些子查询将导致系统运行非常缓慢。我应该使用orderby,并对照前面的结果进行检查。非常感谢。不是所有20列都用来决定选择哪一行,对吗?所以,在选择版本之前,请检查哪个版本更好。如果有很多重复项,并且行很大,那么在SQL中执行此操作可能会更快。检查查询的执行计划并测量性能。
A    B    C
1    8    8
1    7    7
2    10   10
A    B    C
1    x    x
2    10   10
SELECT * FROM (
   SELECT * FROM test GROUP BY a
) table_test;
[Microsoft][ODBC Excel Driver] Cannot group on fields selected with '*'
SELECT * FROM table t1 INNER JOIN
(SELECT A FROM table GROUP BY A HAVING COUNT(A) = 1) as t2 
ON t1.A = t2.A
SELECT * FROM table GROUP BY A 
A    B    C
1    8    8
2    10   10
-- All rows that are unique in column A
select *
from table
where col_a in (select col_a from table group by col_a having count(*)=1)
-- One row per dupe
select * 
from table
where col_a in (select max(col_a) from table group by col_a having count(*)>1)
select a, min(b), min(c)
from (
    select cur.a, cur.b, cur.c
    from YourTable cur
    left outer join YourTable prev
        on cur.a = prev.a
        and (cur.b > prev.b
            or (cur.b = prev.b and cur.c > prev.c))
   where prev.a is null             
) semiunique
group by semiunique.a
select a, min(b), min(c)
from YourTable
group by a
declare @temp as table (
id int identity(1,1),
a int,
b int, 
c int)

insert into @temp
    select 1 as A, 8 as B, 8 as C
    union
    select 1, 7, 7
    union 
    select 2, 10, 10

select a, b, c from @temp
where id in (select MAX(id) from @temp
group by a)
select a, b, c from (
select * 
, ROW_NUMBER() OVER (PARTITION BY A ORDER BY A) as RN
from @temp
) q where rn = 1
select * 
from table T 
where id = (
  select min(id) from table where a = T.a
)
select A, min(B), min(C)
from TABLE
group by A
select A, B, C
from test x
where not exists (select *
                  from test y
                  where y.A = x.A
                        and (y.B < x.B or (y.B = x.B and y.C < x.C))
order by A
select A, B, C from test order by A, B, C
prev_a = None
for a, b, c in get_query_result():
    if a != prev_a:
        prev_a = a
        yield (a, b, c)
$query = "SELECT a,b,c FROM test ORDER BY a,b,c";
$result = odbc_exec($connect, $query);
$prev_a = NULL;  # I don't know what you would normally use here in PHP
while (odbc_fetch_row($result)) {
  $a = odbc_result($result, 1);
  if (is_null($prev_a) or $a != $prev_a) { 
    $b = odbc_result($result, 2);
    $c = odbc_result($result, 3);
    print("A = $a, B = $b, C = $c\n");
    $prev_a = $a;
  }
}
SELECT A, MIN(B), MIN(C) FROM test GROUP BY A
A  B  C
1  2  3
1  4  1 
A  B  C
1  2  1 
Select A
    , Max(b) //Since You don't care about the Value
    , Max(c) //Since You don't care about the Value
From table t
Group By A
SELECT  DISTINCT
    A,
    (SELECT TOP 1 B FROM @Table tB WHERE tb.A = t.A) B,
    (SELECT TOP 1 C FROM @Table tB WHERE tb.A = t.A) C
FROM    @Table t
SELECT UT.[A],
(SELECT TOP 1 B FROM [YourTable] WHERE [YourTable].A= UT.A) AS B,
(SELECT TOP 1 C FROM [YourTable] WHERE [YourTable].A= UT.A) AS C  FROM [YourTable] AS UT GROUP BY UT.[A]