0

我有一个 excel(2010) 表,其中包含如下数据:

trainnumber RowId
2           0
2           1
2           3
4           4
4           5
4           6

我想要一个这样的列表:

RowId
0
4

表示每个 trainnumber 系列的第一个 RowId

我已经尝试构建一个 SELECT 语句,但它不起作用。(我很擅长 SQL 哈哈)

sSQL = "select " & _
              "RowId, " & _
              "(select top 1 trainnumber from @t t2 where t.RowId = t2.RowId order by RowId), " & _
              "from @t t " & _
              "group by RowId"

它告诉我,子选择中有一个语法错误,所以我尝试使用工作表名称,但它给了我同样的错误:

sSQL = "select " & _
              "RowId, " & _
              "(select top 1 trainnumber from @[Conversion$] t2 where t.RowId = t2.RowId order by RowId), " & _
              "from @[Conversion$] t " & _
              "group by RowId"
4

1 回答 1

2

如果你想先为每个,你可以得到min

Select min(rowID)
from youtable
group by trainer_number
;
于 2013-01-31T15:39:19.050 回答