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 |
|
JohnBGood
Starting Member
48 Posts |
Posted - 2010-02-19 : 08:38:36
|
| Not sure how to approach this!!Table A looks like thisuserID, userName, lastLogin1, Joe, 2010-02-17 13:40:36.2872. Sally, 2010-02-18 05:18:22.5303, Bill, null4, Nick, 2010-02-19 04:03:02.040Table B looks like this TIMEBYDAY WeekOFYEAR2011-01-01 00:00:00.000 12011-01-02 00:00:00.000 22011-01-03 00:00:00.000 22011-01-04 00:00:00.000 22011-01-05 00:00:00.000 22011-01-06 00:00:00.000 22011-01-07 00:00:00.000 22011-01-08 00:00:00.000 22011-01-09 00:00:00.000 32011-01-10 00:00:00.000 3 2011-01-11 00:00:00.000 32011-01-12 00:00:00.000 32011-01-13 00:00:00.000 32011-01-14 00:00:00.000 3I would like to build a table that stores the sum of weekly logins. Something like thisWeekOF, SumLogins1/1/10, 01/8,10, 11/15,`0, 01/22/10, 11/20/10, 2Any advice much appreciated!!! |
|
|
JohnBGood
Starting Member
48 Posts |
Posted - 2010-02-19 : 08:44:45
|
| I should add that I have the means to automate a daily query. |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-02-19 : 09:18:54
|
| What is the relation between 2 tables?PBUH |
 |
|
|
JohnBGood
Starting Member
48 Posts |
Posted - 2010-02-19 : 09:28:36
|
| No hard relationship between Table A and B. Table B may not be needed. Not sure. |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-02-19 : 09:31:17
|
Try this;with cteas( select MIN(TIMEBYDAY)as mindate,MAX(TIMEBYDAY)as maxdate from tableA group by WeekOFYEAR)select COUNT(t1.LastLogin)as sumlogins, mindate from cte left join tableB t1 on DATEPART(wk,mindate)=DATEPART(wk,t1.dates) group by mindate PBUH |
 |
|
|
|
|
|
|
|