根据一系列训练数来选择一个不同的RowId

时间:2013-01-31 15:31:51

标签: sql excel-vba vba excel

我有一张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"

它告诉我,subselect中有一个语法错误,所以我尝试使用了sheetname,但它给了我同样的错误:

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

1 个答案:

答案 0 :(得分:2)

如果您想先获得每个,您可以获得min

Select min(rowID)
from youtable
group by trainer_number
;
相关问题