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 |
|
tamancha.1
Starting Member
37 Posts |
Posted - 2010-04-20 : 17:10:44
|
| I have two tables:Table Auser_id time creative site18023231 4/10/2010 8:23:03 1x1 Pixel AOL18023231 4/10/2010 9:33:25 B EA Pogo18023231 4/10/2010 9:33:25 B EA Pogo18023231 4/10/2010 9:33:56 A AOL18023231 4/10/2010 9:33:56 A AOL18023231 4/10/2010 10:23:34 B EA Pogo18023231 4/10/2010 10:23:34 B EA Pogo18023231 4/10/2010 12:17:34 A Weatherbug18023231 4/10/2010 12:17:34 A Weatherbug18023231 4/10/2010 14:46:06 B AOL18023231 4/10/2010 14:46:06 B AOL18023231 4/10/2010 14:50:01 A AOL18023231 4/10/2010 14:50:01 A AOL18023231 4/10/2010 17:51:09 1x1 Pixel AOL18023231 4/10/2010 17:51:09 1x1 Pixel AOLTable Buser_id time creative site18023231 4/10/2010 12:55:00 A WeatherbugI want to get following output:user_id time creative site click18023231 4/10/2010 8:23:03 1x1 Pixel AOL 018023231 4/10/2010 9:33:25 B EA Pogo 018023231 4/10/2010 9:33:25 B EA Pogo 018023231 4/10/2010 9:33:56 A AOL 018023231 4/10/2010 9:33:56 A AOL 018023231 4/10/2010 10:23:34 B EA Pogo 018023231 4/10/2010 10:23:34 B EA Pogo 018023231 4/10/2010 12:17:34 A Weatherbug 118023231 4/10/2010 12:17:34 A Weatherbug 118023231 4/10/2010 14:46:06 B AOL 018023231 4/10/2010 14:46:06 B AOL 018023231 4/10/2010 14:50:01 A AOL 018023231 4/10/2010 14:50:01 A AOL 018023231 4/10/2010 17:51:09 1x1 Pixel AOL 018023231 4/10/2010 17:51:09 1x1 Pixel AOL 0Basically add click =1 in merged file, where everthing is same (user_id, creative, site) and time differs by 1 hour and click=0 otherwise. |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-04-21 : 00:29:42
|
quote: Originally posted by tamancha.118023231 4/10/2010 12:17:34 A Weatherbug 118023231 4/10/2010 12:17:34 A Weatherbug 1
A little more clarification is reqd. Why both Weatherbug is having value of 1 for click. The time difference between the two is not 1 hour. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-21 : 01:33:30
|
| [code]select a.*.case when b.user_id is not null and datediff(hh,a.time,b.time) <= 1 then 1 else 0 end as click from TableA aLEFT JOIN TableB bON b.user_id = a.user_idand b.creative = a.creativeand b.site = a.site[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|