469,326 Members | 1,219 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

COUNT many but display just once?

Hi, I have a table that I insert a member's country into every time
someone signs up. What I'd like to do is pull information from the DB
such that I can see each country and the number of users from each.
For example:

Argentina 10
Brazil 5
Canada 3

I'm having trouble writing the SQL for this...any suggestions?

Thanks,

Erik

Apr 22 '07 #1
2 1820


"Erik Lautier" <la*****@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
Hi, I have a table that I insert a member's country into every time
someone signs up. What I'd like to do is pull information from the DB
such that I can see each country and the number of users from each.
For example:

Argentina 10
Brazil 5
Canada 3
W/o schema it's impossible to say what you want for sure but something like
create table membership
(
country varchar(20),
signup varchar(20)
);

insert into membership values ('Argentina', 'member 1')
insert into membership values ('Argentina', 'member 2')
insert into membership values ('Brazil', 'member 1')
insert into membership values ('Brazil', 'member 1')
insert into membership values ('Brazil', 'member 2')
insert into membership values ('Brazil', 'member 3')
insert into membership values ('Canada', 'member 1')

select country, count(signup) from membership group by country
SELECT COUNTRY, COUNT(signup) from membership group by country

>
I'm having trouble writing the SQL for this...any suggestions?

Thanks,

Erik
--
Greg Moore
SQL Server DBA Consulting Remote and Onsite available!
Email: sql (at) greenms.com http://www.greenms.com/sqlserver.html
Apr 23 '07 #2
That did the trick. Thanks!

On Apr 22, 8:23 pm, "Greg D. Moore \(Strider\)"
<mooregr_deletet...@greenms.comwrote:
"Erik Lautier" <laut...@gmail.comwrote in message

news:11**********************@o5g2000hsb.googlegro ups.com...
Hi, I have a table that I insert a member's country into every time
someone signs up. What I'd like to do is pull information from the DB
such that I can see each country and the number of users from each.
For example:
Argentina 10
Brazil 5
Canada 3

W/o schema it's impossible to say what you want for sure but something like

create table membership
(
country varchar(20),
signup varchar(20)
);

insert into membership values ('Argentina', 'member 1')
insert into membership values ('Argentina', 'member 2')
insert into membership values ('Brazil', 'member 1')
insert into membership values ('Brazil', 'member 1')
insert into membership values ('Brazil', 'member 2')
insert into membership values ('Brazil', 'member 3')
insert into membership values ('Canada', 'member 1')

select country, count(signup) from membership group by country

SELECT COUNTRY, COUNT(signup) from membership group by country
I'm having trouble writing the SQL for this...any suggestions?
Thanks,
Erik

--
Greg Moore
SQL Server DBA Consulting Remote and Onsite available!
Email: sql (at) greenms.com http://www.greenms.com/sqlserver.html

Apr 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Ling Lee | last post: by
8 posts views Thread by Michael | last post: by
1 post views Thread by Fred Morrison | last post: by
2 posts views Thread by rn5a | last post: by
22 posts views Thread by MP | last post: by
3 posts views Thread by Dev | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.