-1

我有下表

mysql> select * from abc;
+---+------+------+
| A | B    | C    |
+---+------+------+
| 2 | 2    | 2    |
| 1 | 2    | 3    |
| 3 | 3    | 2    |
| 4 | 3    | 3    |
+---+------+------+
4 rows in set (0.00 sec)



mysql> select count(distinct *)
    -> from abc
    -> group by a;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '*)
from abc
group by a' at line 1

任何人都可以知道上述查询的正确语法吗?

4

1 回答 1

1

因为DISTINCT您需要提供一个要使用的列DISTINCT

因此,例如在您的情况下:SELECT DISTINCT(a) FROM abc

您想根据唯一值计算表中的行数吗?

SELECT COUNT (DISTINCT a) FROM abc

没有必要,GROUP BY因为DISTINCT已经处理好了。

于 2012-09-16T22:56:26.593 回答