Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>[Edit - altered to use a DateTimeOffset instead]</p> <p>I've come up with the following, starting off with creating the base MyTable:</p> <pre><code>-- Test data creation to match schema &amp; examples create TABLE MyTable ( HitDate DateTimeOffset NOT NULL, IpAddress varchar(15) ) insert into MyTable values ('7/10/2013 8:05:29 -07:00', '111.222.333.444') insert into MyTable values ('7/10/2013 12:05:29 -07:00', '111.222.333.222') insert into MyTable values ('7/9/2013 9:05:29 -07:00', '111.222.333.444') insert into MyTable values ('7/9/2013 10:05:29 -07:00', '111.222.333.555') insert into MyTable values ('7/8/2013 11:05:29 -07:00', '111.222.333.222') insert into MyTable values ('7/8/2013 4:05:29 -07:00', '111.222.333.555') -- actual solution starts here create TABLE #MyTable ( HitDate date, IpAddress varchar(15) ) -- populate data into required format for main query insert into #MyTable SELECT HitDate, IpAddress FROM MyTable -- main query select distinct convert(varchar(10), HitDate, 101) HitDate, ISNULL(dateCounts.counter, 0) NewIPAddresses from #MyTable mainDates left outer join ( select main.HitDate dateValue, count(*) counter from #MyTable main left outer join #MyTable sub on main.IpAddress = sub.IpAddress and main.HitDate &gt; sub.HitDate where sub.IpAddress is null group by main.HitDate ) dateCounts on dateCounts.dateValue = HitDate </code></pre> <p>which gives:</p> <pre><code> HitDate NewIPAddresses -------------- -------------- 07/08/2013 2 07/09/2013 1 07/10/2013 0 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload