根据一系列火车号选择一个不同的RowId [英] Select a distinct RowId based on series of trainnumbers
本文介绍了根据一系列火车号选择一个不同的RowId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张excel(2010)工作表,其中包含以下数据:
I have a excel(2010) sheet with data like this:
trainnumber RowId
2 0
2 1
2 3
4 4
4 5
4 6
我想要一个这样的列表:
And I want a list like this:
RowId
0
4
含义是每个火车编号系列的第一个RowId
Meaning the first RowId of each of the trainnumber series
我尝试构建SELECT语句,但是不起作用.(我很讨厌SQL大声笑)
I've tried build a SELECT statement, but in doesn't work.(I suck at SQL lol)
sSQL = "select " & _
"RowId, " & _
"(select top 1 trainnumber from @t t2 where t.RowId = t2.RowId order by RowId), " & _
"from @t t " & _
"group by RowId"
它告诉我,子选择中存在语法错误,所以我尝试使用工作表名称,但它给了我同样的错误:
It tells me, that there's an Syntax Error in the subselect, so I tried the used the sheetname, but it gives me the same error:
sSQL = "select " & _
"RowId, " & _
"(select top 1 trainnumber from @[Conversion$] t2 where t.RowId = t2.RowId order by RowId), " & _
"from @[Conversion$] t " & _
"group by RowId"
推荐答案
如果每个都需要,您可以获取 min
:
If you want first for each , you can get the min
:
Select min(rowID)
from youtable
group by trainer_number
;
这篇关于根据一系列火车号选择一个不同的RowId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文