mysql 计算表中有多少个不同的国家/地区

chy5wohz  于 2022-12-10  发布在  Mysql
关注(0)|答案(6)|浏览(191)

I have a table like this:

ID  country 
    -------------
    1       US            
    2       Japan           
    3       China           
    4       US          
    5       China

How can one query the table, so that it returns how many different countries are in the table (i.e 3)?

5gfr0r5j

5gfr0r5j1#

The following SQL query will result in counting the number of unique countries in your table.

select  count(distinct country)
from    YourTable
nkkqxpd9

nkkqxpd92#

What you need is to select the amount of unique countries. This is done by selecting all country entries, which are then grouped so there is only one country entry per country name.
SELECT count(country) from countrytable group by country;
This is basically the same as Andomars answer.

pb3s4cty

pb3s4cty3#

you can use this

SELECT country, COUNT( id ) 
   FROM [table_name] GROUP BY country
   LIMIT 0 , 30

Output :

country count(id) 
---------------------
 US       2            
 Japan    1           
 china    2
0yg35tkg

0yg35tkg4#

从国家/地区表中选择计数(不同的国家/地区)

r55awzrz

r55awzrz5#

select count(distinct country) from table1

SELECT count( DISTINCT country )
 FROM table1 c
 WHERE c.item_id = (
 SELECT main_id
 FROM table2
 WHERE main_id = c.item_id )
watbbzwu

watbbzwu6#

从[TableName]中选择计数(不同国家/地区)

相关问题