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.
| Author |
Topic |
|
greenstone90
Starting Member
8 Posts |
Posted - 2010-02-27 : 10:22:11
|
| Hi,I have a website, and am logging every request (including unique username) to my SQL Server database table.The database table columns are:ID, USERNAME, DATETIME, ...I'm trying to write a SqlServer SELECT query that will tell me: How many users come on more than 1 day (repeat customers) to make requests?Idea of how to make this SELECT statement?Does this require a join? How do I strip the "time" part of the date to do the compare?Thanks! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-27 : 10:44:15
|
no need of join. just useSELECT USERNAMEFROM tableGROUP BY USERNAMEHAVING COUNT(DISTINCT DATETIME)>1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-27 : 12:11:12
|
| "How do I strip the "time" part of the date to do the compare?"DATEADD(Day, DATEDIFF(Day, 0 MyDateValue), 0)is the most efficient way to remove the Time from a DateTime datatype object. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
greenstone90
Starting Member
8 Posts |
Posted - 2010-02-28 : 01:21:57
|
| Thanks! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-28 : 04:03:32
|
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|