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
Solved

How to group query by x unit

Posted on 2012-04-13
2
146 Views
Last Modified: 2012-04-17
Hi,

I'm using this little query :
SELECT Sum(PageCount) as NbPage, UserLogon FROM AuditTrail
where CostCentreName = 'Etudiant'
and Timestamp >= convert(datetime, '2011/04/13')
group by UserLogon order by NbPage desc

Open in new window


It show's me how page is printed by user. My SQL is quite old and I can't remember how to "summarize" those data.

I want to know how many users have for exemple :
1 to 500 copies
501 to 1000 copies

etc...

Thx for help.
0
Comment
Question by:Sybux
2 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 37842746
try

select  case when NbPage between 1 and 500 then '1-500'
                       when NbPage between 501 and 1000 then '501-1000'
                        end + ' Copies' , count(*)
from (
 SELECT Sum(PageCount) as NbPage, UserLogon FROM AuditTrail
 where CostCentreName = 'Etudiant'
 and Timestamp >= convert(datetime, '2011/04/13')
 group by UserLogon order by NbPage desc
) t
group by case when NbPage between 1 and 500 then '1-500'
                       when NbPage between 501 and 1000 then '501-1000'
                        end
0
 

Author Closing Comment

by:Sybux
ID: 37855518
Perfect query. Just a little thing, SQL ask for a TOP in the inside query :)
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

790 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