求助!如何按地区进行分组统计?

如图:如何按地区进行分组统计?
亚洲:中国,日本,印度。
美洲:美国,加拿大。
欧洲:英国,德国。图片

order by country

这个你要先把那些国家按洲分好吧

分组,当然是选择group了!

select count(select * from xxx where country='中国' or ...) ,count(...) from xxx 这样行不行

select '亚洲' ,count(id) from table where Country in ('中国','日本','印度') 依次查詢;
最后的方法是建立 地区表 地区表
CREATE TABLE [dbo].code NOT NULL,
[code] varchar NULL,
[c] varchar NULL
) ON [PRIMARY]

CREATE TABLE [dbo].country NULL,
[c] varchar NULL
) ON [PRIMARY]

然後將數據錄入到相應的表裡 (第二個表 u 是洲 c 是國家)

select u,count(u) from (
select a.c g,a.u,b.* from country a right join code b on a.c=b.c) h group by u
先將數據關聯起來,然後根據count函數得到結果

select count(select * from xxx where country='XX' ) ,count(...) from XXX

select country,count(1)from 表名 group by country