SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 count distinct values
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pelegk2
Aged Yak Warrior

Israel
723 Posts

Posted - 01/08/2013 :  09:12:30  Show Profile  Visit pelegk2's Homepage  Send pelegk2 an ICQ Message  Reply with Quote
i have table with :
date,personalid
i want to count for each day
1)how many rows there are
2)how many distinct personalid in a day

what the best way to do it?

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 01/08/2013 :  09:26:57  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
select count(*), count(distinct personalid), date
from tbl
group by date


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

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/08/2013 :  23:49:01  Show Profile  Reply with Quote
does date field store timepart too? if yes,

select count(*), count(distinct personalid),  dateadd(dd,datediff(dd,0,[date]),0)
from tbl
group by dateadd(dd,datediff(dd,0,[date]),0)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

pelegk2
Aged Yak Warrior

Israel
723 Posts

Posted - 01/09/2013 :  03:58:35  Show Profile  Visit pelegk2's Homepage  Send pelegk2 an ICQ Message  Reply with Quote
10x all
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.3 seconds. Powered By: Snitz Forums 2000