mysql count unique row values

前端 未结 5 980
孤街浪徒
孤街浪徒 2021-02-19 03:30

TABLE quotation

id  clientid
1   25
2   25
3   25
4   25
5   26

How can I query how many different clients exist in TABLE qu

5条回答
  •  耶瑟儿~
    2021-02-19 03:33

    I tried the following on a MySQL 5.x database.

    id is an integer and clientid is an integer. I populated with two rows:

    id  clientid
    1   25
    2   25
    

    This SQL query will print the rows that have exactly 2 elements:

    select * from test1 group by clientid having count(*) = 2;
    

    If you want 2 or more elements, replace = 2 in the example above with >= 2.

    select * from test1 group by clientid having count(*) >= 2;
    

提交回复
热议问题