Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 筛选excel表格中的唯一集_Sql_Excel_Filter_Excel Formula_Business Intelligence - Fatal编程技术网

Sql 筛选excel表格中的唯一集

Sql 筛选excel表格中的唯一集,sql,excel,filter,excel-formula,business-intelligence,Sql,Excel,Filter,Excel Formula,Business Intelligence,我有一个excel表格,如下所示: Row Name 1 uniqueName001_vid1.mpg 2 uniqueName001.mpg 3 uniqueName002_vid1.mpg 4 uniqueName002_vid2.mpg 5 uniqueName002.mpg 我试图找出如何在表中标识和标记(给出唯一ID)包含相同uniqueName的集合。例如,行的1和2将是一个集合,行的3、4和5将是另一个集合 我的理想结果是: Row Name

我有一个excel表格,如下所示:

Row  Name 
 1   uniqueName001_vid1.mpg
 2   uniqueName001.mpg
 3   uniqueName002_vid1.mpg
 4   uniqueName002_vid2.mpg
 5   uniqueName002.mpg
我试图找出如何在表中标识和标记(给出唯一ID)包含相同uniqueName的集合。例如,行的1和2将是一个集合,行的3、4和5将是另一个集合

我的理想结果是:

Row  Name                     UID
 1   uniqueName001_vid1.mpg   SET1
 2   uniqueName001.mpg        SET1
 3   uniqueName002_vid1.mpg   SET2
 4   uniqueName002_vid2.mpg   SET2
 5   uniqueName002.mpg        SET2
我可以在excel中运行SQL查询,如果这是比excel公式更好的选项


非常感谢您的任何建议

如果一切都以uniqueNameXXX开头,那就很容易了

Row Name                    UniqueName      Unique#             UID
1   uniqueName001_vid1.mpg  =LEFT(F4;13)    =IF(G3<>G4;H3+1;H3) ="UID"&H4
行名称唯一性#UID
1 uniqueName001_vid1.mpg=左(F4;13)=如果(G3G4;H3+1;H3)=“UID”和H4

如果不是,那么您应该定义如何获取uniqueName,如果所有内容都以uniqueNameXXX开头,那么这很容易

Row Name                    UniqueName      Unique#             UID
1   uniqueName001_vid1.mpg  =LEFT(F4;13)    =IF(G3<>G4;H3+1;H3) ="UID"&H4
行名称唯一性#UID
1 uniqueName001_vid1.mpg=左(F4;13)=如果(G3G4;H3+1;H3)=“UID”和H4

如果没有,那么您应该定义如何获取uniqueName

您可以使用
VBA
执行该任务

我给你做了一个小工具。注意可编辑部分 根据声明

这个工具监听数字——意味着,我希望你的模式总是和你在问题中写的一样

告诉我这是否有帮助:

Sub ExtractIdFromString()

    Dim strYourColumn As String
    Dim intYourStartRow As Integer
    Dim intYourLengthOfId As Integer
    Dim strYourSetColumn As String
    Dim strYourPrefix As String
    Dim strString As String
    Dim intStringLength As Integer
    Dim intStringDigitPosition As Integer
    Dim intParserPosition As Integer
    Dim strParser As String
    Dim i As Integer
    Dim strUniqueString As String
    Dim rngCell As Range
    Dim rngSetCell As Range
    Dim strIndex As String
    Dim lngCounter As Long


    ''''editable values''''
    strYourColumn = "B"    'Your name column, must be alphabethical
    intYourStartRow = 1    'Startrow of your block, must not be 0
    intYourLengthOfId = 3  'The amount of digits in your ID, must be > 1
    strYourSetColumn = "C"    'The column, where the ID will be inserted, must be numerical (use A = 1, Z = 26)
    strYourPrefix = "SET"   'Prefix of your set's ID
    ''''end of editable values''''




    'Set the format of the ID column to text
    Range(strYourColumn & ":" & strYourColumn).NumberFormat = "@"

    'traverse through the names column
    For Each rngCell In Range(strYourColumn & ":" & strYourColumn)

        'initialize / reset parser
        intParserPosition = 1

        'get the actual string to value
        strString = rngCell.Value

        'End loop on empty cell
        If strString = "" Then
            GoTo massRename
        End If

        'get the string's length
        intStringLength = Len(strString)

        'parse through the string
        For intStringDigitPosition = 1 To intStringLength Step 1

            'end loop if the string is parsed without a result
            If intParserPosition > intStringLength Then
                Exit For
            End If

            'get single digit of the string
            strParser = Mid(strString, intParserPosition, 1)

            'listen on numbers
            If IsNumeric(strParser) Then

                'traverse through the expected ID slots
                For i = intParserPosition To intParserPosition + intYourLengthOfId - 1 Step 1

                    'listen for non numerical chars in the expected ID
                    If Not IsNumeric(Mid(strString, i, 1)) Then

                        'allow your titles to include numbers
                        GoTo SkipSingleNumerics

                    End If

                Next

                'get the unique prototype of the string
                strUniqueString = Mid(strString, 1, intParserPosition + intYourLengthOfId - 1)                    

                'write the unique name in a specified column
                Range(strYourSetColumn & rngCell.Row).Value = strUniqueString

            End If

'Skip numbers in the string, that dont dont match the ID pattern (optional)
SkipSingleNumerics:

            'traverse trough the word
            intParserPosition = intParserPosition + 1

        Next
    Next

'Rename and index equal values
massRename:

    lngCounter = 1
    'traverse through the set list
    For Each rngSetCell In Range(strYourSetColumn & ":" & strYourSetColumn)

        'end condition
        If rngSetCell.Value = "" Then
            Exit For
        End If

        'store value in variable to save it from overwriting
        strIndex = rngSetCell.Value

        'start another traversal instance
        For Each rngCell In Range(strYourSetColumn & ":" & strYourSetColumn)

            'end condition
            If rngCell.Value = "" Then
                Exit For
            End If

            'listen if both instances match
            If strIndex = rngCell.Value Then

                'rename the value
                rngCell.Value = strYourPrefix & lngCounter

            End If
        Next

        'increase unique counter
        lngCounter = lngCounter + 1
    Next
End Sub

在Excel 2010中测试

您可以使用
VBA
执行该任务

我给你做了一个小工具。注意可编辑部分 根据声明

这个工具监听数字——意味着,我希望你的模式总是和你在问题中写的一样

告诉我这是否有帮助:

Sub ExtractIdFromString()

    Dim strYourColumn As String
    Dim intYourStartRow As Integer
    Dim intYourLengthOfId As Integer
    Dim strYourSetColumn As String
    Dim strYourPrefix As String
    Dim strString As String
    Dim intStringLength As Integer
    Dim intStringDigitPosition As Integer
    Dim intParserPosition As Integer
    Dim strParser As String
    Dim i As Integer
    Dim strUniqueString As String
    Dim rngCell As Range
    Dim rngSetCell As Range
    Dim strIndex As String
    Dim lngCounter As Long


    ''''editable values''''
    strYourColumn = "B"    'Your name column, must be alphabethical
    intYourStartRow = 1    'Startrow of your block, must not be 0
    intYourLengthOfId = 3  'The amount of digits in your ID, must be > 1
    strYourSetColumn = "C"    'The column, where the ID will be inserted, must be numerical (use A = 1, Z = 26)
    strYourPrefix = "SET"   'Prefix of your set's ID
    ''''end of editable values''''




    'Set the format of the ID column to text
    Range(strYourColumn & ":" & strYourColumn).NumberFormat = "@"

    'traverse through the names column
    For Each rngCell In Range(strYourColumn & ":" & strYourColumn)

        'initialize / reset parser
        intParserPosition = 1

        'get the actual string to value
        strString = rngCell.Value

        'End loop on empty cell
        If strString = "" Then
            GoTo massRename
        End If

        'get the string's length
        intStringLength = Len(strString)

        'parse through the string
        For intStringDigitPosition = 1 To intStringLength Step 1

            'end loop if the string is parsed without a result
            If intParserPosition > intStringLength Then
                Exit For
            End If

            'get single digit of the string
            strParser = Mid(strString, intParserPosition, 1)

            'listen on numbers
            If IsNumeric(strParser) Then

                'traverse through the expected ID slots
                For i = intParserPosition To intParserPosition + intYourLengthOfId - 1 Step 1

                    'listen for non numerical chars in the expected ID
                    If Not IsNumeric(Mid(strString, i, 1)) Then

                        'allow your titles to include numbers
                        GoTo SkipSingleNumerics

                    End If

                Next

                'get the unique prototype of the string
                strUniqueString = Mid(strString, 1, intParserPosition + intYourLengthOfId - 1)                    

                'write the unique name in a specified column
                Range(strYourSetColumn & rngCell.Row).Value = strUniqueString

            End If

'Skip numbers in the string, that dont dont match the ID pattern (optional)
SkipSingleNumerics:

            'traverse trough the word
            intParserPosition = intParserPosition + 1

        Next
    Next

'Rename and index equal values
massRename:

    lngCounter = 1
    'traverse through the set list
    For Each rngSetCell In Range(strYourSetColumn & ":" & strYourSetColumn)

        'end condition
        If rngSetCell.Value = "" Then
            Exit For
        End If

        'store value in variable to save it from overwriting
        strIndex = rngSetCell.Value

        'start another traversal instance
        For Each rngCell In Range(strYourSetColumn & ":" & strYourSetColumn)

            'end condition
            If rngCell.Value = "" Then
                Exit For
            End If

            'listen if both instances match
            If strIndex = rngCell.Value Then

                'rename the value
                rngCell.Value = strYourPrefix & lngCounter

            End If
        Next

        'increase unique counter
        lngCounter = lngCounter + 1
    Next
End Sub
在Excel 2010中测试

我不明白=IF(G3G4;H3+1;H3)是如何工作的,但它引导我朝着正确的方向前进!我不明白=IF(G3G4;H3+1;H3)是如何工作的,但它把我引向了正确的方向!