Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL Count

Author  Topic 

lakers34kb
Starting Member

15 Posts

Posted - 2010-01-29 : 22:14:05
I have an OrderDate column and I need to filter it so it only brings up a certain month.

and my other problem is


I have a column of customers and another column of countries. There are many customers in a certain country. I need to know the total number of customers in each country.


thanks for the help

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-29 : 22:37:04
first problem

where datepart(month, OrderDate) = <required month>


other problem

select country, count(*)
from sometable
group by country



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

lakers34kb
Starting Member

15 Posts

Posted - 2010-01-29 : 22:51:01
how do I make the 2nd one sort from the new counting column
Go to Top of Page

lakers34kb
Starting Member

15 Posts

Posted - 2010-01-29 : 23:17:06
I figured it out... thanks for your help

Solution:

SELECT Country, count(*)as CountryCount
FROM Customers
GROUP BY Country ORDER BY CountryCount Desc
Go to Top of Page
   

- Advertisement -