473,473 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Grouping Aggregate Query with multiple Criteria

2 New Member
My table consists of DeviceID, Identification_Number, Amt.

A query needed which will display the count of Amt=0 and count of Amt>0 and Amt<10, Count of Amt>10 and Amt<100, Count of Amt>100 and Amt<1000.
May 7 '19 #1
1 911
twinnyfo
3,653 Recognized Expert Moderator Specialist
See your earlier post concerning your fortunate-ness in my response. Again, I assume you have no idea where to start.

What you are looking for is called a "CrossTab Query, which is similar to a Pivot Table in Excel. It aggregates values across various fields in your Table and can categorize based upon the criteria your provide. I can't image that you would have stumbled upon this solution all by yourself if you are new to SQL. Here is what I have that may suit your needs:

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(TableName.DeviceID) AS CountOfDeviceID 
  2. SELECT "Device Count" AS DeviceCount 
  3. FROM TableName 
  4. GROUP BY "Device Count" 
  5. PIVOT IIf([Amt]=0,"0",IIf([Amt]>0 And [Amt]<=10,"1-10",IIf([Amt]>10 And [Amt]<=100,"11-100",IIf([Amt]>100 And [Amt]<=1000,"101-1000",">1000"))));
You will have to replace "TableName" with the name of your table.

The key in this query is the expression after the "PIVOT" Statement. This splits up the values of your table based upon the Amt value in your table, provides a "heading" for that value and then counts hte number of entries.

Hope this hepps!
May 7 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Furphy | last post by:
Could someone assist with getting the count function working correctly in this example please. I know the count function will return all rows that do not have null values, but in this case I want...
1
by: Irfan | last post by:
Hello, I am having some problem with count function. I have a report in which has grouping by a person wise and sub grouping in invoied status e.g.. the output will be Irfan Records (First...
9
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
9
by: Alpha | last post by:
C# doesn't allow multiple condition in a single if ? Or did I make a mistake with my syntax? It keep giving me syntax error when I put "and" or "or" in the if statemnt for multiple condition...
4
by: Danielle | last post by:
I have data like this in a two column temporary table - ID Age 23586 3 23586 3 23586 2 23586 2 23586 1 23586 1
6
by: Allerdyce.John | last post by:
Hi, How can I put multiple condition in if statement? I try this, but I can't get that to work. if ( (str != " ") && (str != "") ): Any help is appreciated.
1
by: AZKing | last post by:
Hi all, I am trying to create a query that will count the number of items in a certain field. For example, the number of cars listed as "Ford" in the USA. I can do it for just one item, but there...
7
by: wertqt | last post by:
Hi, i used the COUNT function to return the number of rows that satisfy the conditions set. This method works but when i press the load button again, it will still gives me another same set of...
4
by: Hatfield | last post by:
I've got an assignment that has me making queries on a table about tornadoes that has 41391 records. The setup for the query is this: "We desire to find out about the tornadoes for each year in...
1
greeni91
by: greeni91 | last post by:
Hi, I am currently trying to create a report that list all the Features that have been checked and the metrology used to check said feature. I have created a UNION query that will combine the...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.