0

我有以下 SQL 字符串:

sSQL_Select = "SELECT distinct local_insurer, subsidiary, location FROM T_WILMA WHERE PARENT=" & lParent_ID & _
                    " AND ACC_YEAR=" & lAcc_Year_ID & " AND ZOMBIE = FALSE GROUP BY local_insurer ORDER BY " & _
                    "subsidiary ASC, location ASC;"

Access 会引发错误,因为我无法执行此操作。
我需要的是具有不同本地保险公司的所有记录,但按子公司和位置字段的字母顺序排列。
不知何故,我似乎从来没有得到正确的结果。
有任何想法吗?

4

2 回答 2

1

GROUP BY local_insurer从查询中删除。(distinct将确保您仅获得唯一的值组合。)

于 2013-06-28T08:49:21.547 回答
0

您收到错误的原因是您没有在 GROUP BY 中包含 SELECT 中的所有字段。例如,如果您 SELECT a,b,c ,则需要 GROUP BY a,b,c (或 c,b,a...) 。

sSQL_Select = "SELECT distinct local_insurer, subsidiary, location FROM T_WILMA WHERE PARENT=" & lParent_ID & _
                " AND ACC_YEAR=" & lAcc_Year_ID & " AND ZOMBIE = FALSE GROUP BY local_insurer, subsidiary, location ORDER BY " & _
                "subsidiary ASC, location ASC;"
于 2013-06-28T09:00:04.953 回答