Aggregate Function on Uniqueidentifier (GUID)

后端 未结 5 1389
日久生厌
日久生厌 2021-02-02 05:41

Let\'s say I have the following table:

category | guid
---------+-----------------------
   A     | 5BC2...
   A     | 6A1C...
   B     | 92A2...
5条回答
  •  遥遥无期
    2021-02-02 06:26

    Just cast it as a BINARY(16).

    SELECT category, MIN(CAST(guid AS BINARY(16)))
    FROM myTable
    GROUP BY category
    

    You can cast it back later if necessary.

    WITH CategoryValue
    AS
    (    
        SELECT category, MIN(CAST(guid AS BINARY(16)))
        FROM myTable
        GROUP BY category
    )
    SELECT category, CAST(guid AS UNIQUEIDENTIFIER)
    FROM CategoryValue
    

提交回复
热议问题