在SQL中列出特定值

时间:2016-09-22 02:56:27

标签: mysql sql

我这里有一张名为TEST的表格。我想显示我家的左撇子和惯用右手的人数。

怎么会这样做?这是我做的:

+---------+---------+
|  NAME   |  HANDED |
+---------+---------+
| Jeffrey |    R    |
| Ashley  |    L    |
|  Bob    |    R    |
|  Dad    |    R    |
|  Mom    |    R    |
+---------+---------+

SELECT HANDED, COUNT(HANDED) AS COUNT_HANDED
FROM TEST
WHERE HANDED = 'L' OR HANDED = 'R';

我希望输出如下:

+---------+--------------+
|  HANDED | COUNT_HANDED |
+---------+--------------+
|    L    |       1      |
|    R    |       4      |
+---------+--------------+

我该怎么办?

1 个答案:

答案 0 :(得分:0)

简单!

{{1}}