Solved

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

Posted on 2011-02-25
1
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

734 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