Solved

Restructing a SQL query reporting 7 and 30 day counts to reporting daily counts over 15 days:

Posted on 2011-02-25
1
327 Views
Last Modified: 2012-08-13
Hello, I have a query with the code:
SELECT Imported.[Modified By],
Count(1) AS UserCount,
(Select Count (*) from Imported) AS TotCount,
Round([Usercount]*100/[TotCount],2) AS Userpercent,
Sum(IIf([Date Modified]>Date()-7,1,0)) AS Last7Days,
Sum(IIf([Date Modified]>Date()-30,1,0)) AS Last30Days
FROM Imported
WHERE (((Imported.[Modified By]) Is Not Null))
GROUP BY Imported.[Modified By];

which reports to me several counts of user progress in a database (total, 7 and 30 day counts).   I would like to modify the code so that I can report a histogram reporting the number of records reviewed by a user over each of the last 15 days (i.e Day 1 user reviewed 10 records, Day 2 user reviewed 0 records, day 3 user reviewed 3 records etc... [only a sum of the records reviewed that day[).  Does anyone know how I should set up this SQL query to address this problem?  Bonus points if you can get the fields to be called by their appropriate name (i.e. Day 1 = January 2, 2011 Day 2 = January 3, 2011 etc...)

Thanks so much for any comments,
Bevo
0
Comment
Question by:Bevos
1 Comment
 

Accepted Solution

by:
Bevos earned 0 total points
ID: 34980759
Fixed this myself:

DaSELECT Imported.[Modified By],
Count(1) AS UserCount,
(Select Count (*) from Imported) AS TotCount,
Round([Usercount]*100/[TotCount],2) AS Userpercent,
Sum(IIf([Date Modified]=Date()-14,1,0)) AS Day14,
Sum(IIf([Date Modified]=Date()-13,1,0)) AS Day13,
Sum(IIf([Date Modified]=Date()-12,1,0)) AS Day12,
Sum(IIf([Date Modified]=Date()-11,1,0)) AS Day11,
Sum(IIf([Date Modified]=Date()-10,1,0)) AS Day10,
Sum(IIf([Date Modified]=Date()-9,1,0)) AS Day9,
Sum(IIf([Date Modified]=Date()-8,1,0)) AS Day8,
Sum(IIf([Date Modified]=Date()-7,1,0)) AS Day7,
Sum(IIf([Date Modified]=Date()-6,1,0)) AS Day6,
Sum(IIf([Date Modified]=Date()-5,1,0)) AS Day5,
Sum(IIf([Date Modified]=Date()-4,1,0)) AS Day4,
Sum(IIf([Date Modified]=Date()-3,1,0)) AS Day3,
Sum(IIf([Date Modified]=Date()-2,1,0)) AS Day2,
Sum(IIf([Date Modified]=Date()-1,1,0)) AS Day1,
Sum(IIf([Date Modified]=Date(),1,0)) AS Day0,
Sum(IIf([Date Modified]>Date()-7,1,0)) AS Last7Days,
Sum(IIf([Date Modified]>Date()-30,1,0)) AS Last30Days
FROM Imported
WHERE (((Imported.[Modified By]) Is Not Null))
GROUP BY Imported.[Modified By];
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Viewers will learn how the fundamental information of how to create a table.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question