Solved

How to group query by x unit

Posted on 2012-04-13
2
148 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
[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
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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