Solved

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

Posted on 2011-02-25
1
325 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now