来自差异值SQL的SELECT,DISTINCT和COUNT数据

时间:2017-11-09 23:40:25

标签: mysql

如何区分值,并根据此数据计算来自差异值的数据

   NAME |                  NAME | TOTAL
    A   |                   A   |   4
    A   |                   B   |   2
    A   |     INTO THIS
    A   |
    B   |
    B   |

我已经尝试过此查询

SELECT DISTINCT(name) ,COUNT(DISTINCT(NAME)) FROM tbl_a

但它只显示,即使我使用分组,并按...排序。

NAME |  TOTAL
 A   |    4

2 个答案:

答案 0 :(得分:2)

你可以这样做:

select NAME, COUNT(NAME)  
from tbl_a
group by NAME;

答案 1 :(得分:0)

SELECT COUNT(DISTINCT name_column) AS some_alias FROM table_name