Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 18,934 of 19,505    |
|    migurus to Ross Presser    |
|    Re: how many new IDs participated    |
|    14 Aug 13 13:27:09    |
      From: migurus@yahoo.com              On Wednesday, August 14, 2013 2:18:21 AM UTC-7, Ross Presser wrote:       > On Tuesday, August 13, 2013 9:43:44 PM UTC-4, migurus wrote:       >       > > I have a series of Customer ID / Date records showing participation of       customers on the daily basis. I need to find out how many new customers       participated each day.       >       > [snip]       >       > > Any ideas? I was trying to self-join but can not quite wrap my brain       around it.       >       > >       >       > > Thanks in advance.       >       >       >       > WITH X1 AS (       >       > SELECT ID, MIN(DT) AS FirstDT       >       > FROM @T AS T       >       > GROUP BY ID       >       > ),       >       > X2 AS (       >       > SELECT DISTINCT DT FROM @T AS T       >       > )       >       > SELECT X2.DT, COUNT(X1.ID)       >       > FROM X2       >       > LEFT JOIN X1 ON X2.DT = X1.FirstDT       >       > GROUP BY X2.DT       >       >       >       > DT       >       > ---------- -----------       >       > 2013-08-07 2       >       > 2013-08-08 0       >       > 2013-08-09 1       >       > 2013-08-12 0       >       > 2013-08-13 1       >       > Warning: Null value is eliminated by an aggregate or other SET operation.       >       >       >       > (5 row(s) affected)       >       >       >       > The value for 2013-08-09 is accurate; look closely at your data, 332551 is       represented twice on that day.              Thank you!       Works perfectly well.              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca