Friday, March 30, 2012

question about selecting records

I have a mssql database like this:

Table1:
ID GuestName Agent CheckInDate OtherColumn
1 Guest 1 Peter 1/11/2005 whatever
2 Guest 2 Peter 1/11/2005 whatever
3 Guest 3 John 1/11/2005 whatever
4 Guest 4 John 1/13/2005 whatever
5 Guest 5 Peter 1/11/2005 whatever

I want to display it group by same Agent and CheckInDate. Like this:

Agent CheckInDate Records
Peter 1/11/2005 3
John 1/11/2005 1
John 1/13/2005 1

How can I do this? Please help, thank you.

select agent,checkindate,count(agent) Records
from <table>
group by agent,checkindate
|||Thank you. And there's another question. The CheckInDate values has time value in it. for example, 1/11/2005 1:15:45PM. If I use GROUP BY CheckInDate, the time value matters. How can ingore time value and just GROUP BY date value?|||cast or convert it to a varchar|||CONVERT(VARCHAR(12), myDateColumn, 101)

No comments:

Post a Comment