选择distinct * error mysql

时间:2012-09-16 22:42:10

标签: mysql

我有下表

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

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

1 个答案:

答案 0 :(得分:1)

对于DISTINCT,您需要提供一个使用DISTINCT的列。

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

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

SELECT COUNT (DISTINCT a) FROM abc

由于GROUP BY已经处理了此问题,因此无需DISTINCT