db 引擎可以拆分Labels
字段的两个组件。
SELECT
Left(Labels, 6) AS prefix_string
Val(Right(Labels, 3)) AS suffix_nmbr
FROM LabelInfo;
将其用作查询的子GROUP BY
查询。
SELECT
sub.prefix_string,
Max(sub.suffix_nmbr) AS MaxOfSuffix_nmbr
FROM
(
SELECT
Left(Labels, 6) AS prefix_string
Val(Right(Labels, 3)) AS suffix_nmbr
FROM LabelInfo
) AS sub
GROUP BY sub.prefix_string;
如果在您的 c# 客户端代码中重新组合这两个部分不方便,您可以让 db 引擎将所有内容作为子查询来完成。
SELECT
sub2.prefix_string
& Format(sub2.MaxOfSuffix_nmbr, '000')
AS labels_alias
FROM
(
SELECT
sub1.prefix_string,
Max(sub1.suffix_nmbr) AS MaxOfSuffix_nmbr
FROM
(
SELECT
Left(Labels, 6) AS prefix_string
Val(Right(Labels, 3)) AS suffix_nmbr
FROM LabelInfo
) AS sub1
GROUP BY sub1.prefix_string
) AS sub2;