|
theapostle
Starting Member
2 Posts |
Posted - 2010-01-23 : 22:19:24
|
| I'm a complete noob. I have the following scenario. I need to be able return only the non-duplicate urls created by each user (name) grouped by url count within the last 24 hours (showing the first occurrence datetime of the url). I hope that makes sense. Appreciate any insight. Thanks.id url name date7fe5f6c5-8874-4911-95de-2ba489ecfc5a http://www.google.com/ joe 1/23/2010 10:56:31 AM40dc0abf-be05-47a3-92d1-4f8332ba98af http://www.google.com/ joe 1/23/2010 11:43:42 PM1664e2d4-8efa-42b4-b605-76338ec2cca4 http://www.google.com/ joe 1/23/2010 10:56:30 AMd59ec0d3-fbe2-4a60-a700-6a0426566825 http://www.msn.com/ sally 1/23/2010 10:35:19 AMccd6634b-dbd4-4adc-a4f1-db764ecec2b7 http://www.msn.com/ frank 1/23/2010 12:49:11 AMc8aa3d15-d448-4782-8563-022026f0012b http://www.bing.com/ mary 1/23/2010 1:50:26 AM5475a767-e747-463a-b4ff-5ee312d40ca8 http://www.google.com/ ted 1/23/2010 9:16:07 PMd160fed0-424d-4e74-a1a2-eec1de5a5dec http://www.msn.com/ eddie 1/23/2010 5:01:22 PMBased on this data (and filtering within the last 24 hours) I would try to return:url count first_occurrence_datehttp://www.google.com/ 2 1/23/2010 10:56:30 AMhttp://www.msn.com/ 3 1/23/2010 10:35:19 AMhttp://www.bing.com/ 1 1/23/2010 1:50:26 AMUSE [tester];GOSET ANSI_NULLS ON;GOSET QUOTED_IDENTIFIER ON;GOCREATE TABLE [dbo].[test] ([id] uniqueidentifier ROWGUIDCOL NULL DEFAULT (newid()),[url] nvarchar(255) NOT NULL,[name] nchar(25) NOT NULL,[date] datetime2(7) NULL)ON [PRIMARY]WITH (DATA_COMPRESSION = NONE);GOinsert into [dbo].[test]([id],[url],[name],[date]) values ('7fe5f6c5-8874-4911-95de-2ba489ecfc5a',N'http://www.google.com/',N'joe ','2010-01-23 10:56:31')insert into [dbo].[test]([id],[url],[name],[date]) values ('40dc0abf-be05-47a3-92d1-4f8332ba98af',N'http://www.google.com/',N'joe ','2010-01-23 23:43:42')insert into [dbo].[test]([id],[url],[name],[date]) values ('1664e2d4-8efa-42b4-b605-76338ec2cca4',N'http://www.google.com/',N'joe ','2010-01-23 10:56:30')insert into [dbo].[test]([id],[url],[name],[date]) values ('d59ec0d3-fbe2-4a60-a700-6a0426566825',N'http://www.msn.com/',N'sally ','2010-01-23 10:35:19')insert into [dbo].[test]([id],[url],[name],[date]) values ('ccd6634b-dbd4-4adc-a4f1-db764ecec2b7',N'http://www.msn.com/',N'frank ','2010-01-23 00:49:11')insert into [dbo].[test]([id],[url],[name],[date]) values ('c8aa3d15-d448-4782-8563-022026f0012b',N'http://www.bing.com/',N'mary ','2010-01-23 01:50:26')insert into [dbo].[test]([id],[url],[name],[date]) values ('5475a767-e747-463a-b4ff-5ee312d40ca8',N'http://www.google.com/',N'ted ','2010-01-23 21:16:07')insert into [dbo].[test]([id],[url],[name],[date]) values ('d160fed0-424d-4e74-a1a2-eec1de5a5dec',N'http://www.msn.com/',N'eddie ','2010-01-23 17:01:22') |
|