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 2005 Forums
 Transact-SQL (2005)
 Count unique Records

Author  Topic 

sgraves3
Starting Member

1 Post

Posted - 2007-12-05 : 10:58:59
I need to count the number of stores that sold an item over the period of a month. The table has unique records for each week. So I need to count a store that sold this particular item as 1 even if they sold the item for every week of the month.
Is there an easy way to perform this function?

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-05 : 11:01:01
[code]select count(distinct store)[/code]


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

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-12-05 : 11:02:20
select item_id, count(distint store_id)
from tbl
where datediff(mm, @month, solddate) = 0
group by item_id


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -