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
 General SQL Server Forums
 New to SQL Server Programming
 Group by query

Author  Topic 

qutesanju
Posting Yak Master

193 Posts

Posted - 2010-11-17 : 04:27:11
Using one query i'm getting result as

Name count Timstamp
Eric 1 11/15/2010 3:24:13 AM
Enrique 1 11/15/2010 3:32:28 AM
Rick 1 11/16/2010 12:31:52 AM
Rick 1 11/16/2010 12:32:02 AM

but i need to do group by as

Name count Timstamp
Eric 1 11/15/2010
Enrique 1 11/15/2010
Rick 2 11/16/2010

ignoring timstamp and it should group based on date only

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-11-17 : 04:34:00
Which SQL Server Version are you using?
Is it 2008 or earlier?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-11-17 : 04:34:10
select name,count(count),CONVERT(varchar(20),Timstamp,110)
from yourtable
group by name,CONVERT(varchar(20),Timstamp,110)


PBUH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-17 : 04:36:45
Post the query that you have used

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-17 : 04:38:35
select name,count(count),dateadd(day,datediff(day,0,datecol),0) from yourtable
group by name,dateadd(day,datediff(day,0,datecol),0)



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-11-17 : 05:05:48
SELECT Name, SUM([Count]) [Count], Timstamp FROM
(
SELECT Name, [Count], CONVERT(VARCHAR(10), Timstamp, 101) Timstamp FROM TestTable WITH(NOLOCK)
) A
GROUP BY Name, Timstamp

Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page

qutesanju
Posting Yak Master

193 Posts

Posted - 2010-11-17 : 06:58:31
great madhivanan,vaibhavktiwari83......
it worked!!!
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-12-03 : 06:09:00
Thanks

Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page
   

- Advertisement -