如何计算Access查询中字段中的唯一项?

时间:2022-11-29 21:19:27

My Table: table1

我的表:table1

ID  Name  Family
1   A     AA
2   B     BB
3   A     AB
4   D     DD
5   E     EE
6   A     AC

SQL command on Access:

Access上的SQL命令:

select count(*) from table1

Output: ------------> True
6 row(s)

输出:------------>真6行

I tried to count unique names:

我试图计算独特的名字:

Expected output: 4 row(s)

预期产量:4排

select count(distinct Name) from table1

Output on Access: ------------> Error

Access上的输出:------------>错误

What changes do I need to make to my query?

我需要对查询进行哪些更改?

2 个解决方案

#1


33  

Try this

尝试这个

SELECT Count(*) AS N
FROM
(SELECT DISTINCT Name FROM table1) AS T;

Read this for more info.

阅读本文以获取更多信息。

#2


7  

Access-Engine does not support

Access-Engine不支持

SELECT count(DISTINCT....) FROM ...

You have to do it like this:

你必须这样做:

SELECT count(*) 
FROM
(SELECT DISTINCT Name FROM table1)

Its a little workaround... you're counting a DISTINCT selection.

它有点解决方法......你在计算DISTINCT的选择。

#1


33  

Try this

尝试这个

SELECT Count(*) AS N
FROM
(SELECT DISTINCT Name FROM table1) AS T;

Read this for more info.

阅读本文以获取更多信息。

#2


7  

Access-Engine does not support

Access-Engine不支持

SELECT count(DISTINCT....) FROM ...

You have to do it like this:

你必须这样做:

SELECT count(*) 
FROM
(SELECT DISTINCT Name FROM table1)

Its a little workaround... you're counting a DISTINCT selection.

它有点解决方法......你在计算DISTINCT的选择。