Solved

Difficult  SQL  QUERY

Posted on 1998-08-06
2
190 Views
Last Modified: 2010-04-30
Experts:



I have to make a query for table in Access , like this:

City            Orders
-----------------------------
A            200
B            500
A            1200
A            700
B            900
C            400
..
..

Using one or two query to reach result like this:

City             Orders<=500      Orders>500
------------------------------------------
A             1                2
B             1             1
C             1                  

Please answer as soon as possible.

thanks
0
Comment
Question by:radstad
2 Comments
 
LVL 1

Expert Comment

by:Anita030598
ID: 1468149
I remember reading the exact same question in MS Access section like yesterday or the day before. Did you post it there as well?
But I see that you registered with EE just today! Have you searched it in MS Access Section.
0
 
LVL 1

Accepted Solution

by:
awd earned 200 total points
ID: 1468150
Here is ONE solution to your problem.  Just past the text of the 2 queries into the SQL design screen.  This assumes that your table is named "tblOrders", col 1 is "City", col 2 is "Orders".

******************************************************************************************
"qrySplit" is as follows:

     SELECT City, Count(*) AS "Orders <= 500", 0 AS "Orders > 500"
     FROM tblOrders
     WHERE tblOrders.Orders <= 500
     GROUP By City

     UNION

     SELECT City,  0, Count(*)
     FROM tblOrders
     WHERE tblOrders.Orders > 500
     GROUP By City;
*************************************************************************************
qryCombine is as follows:

     SELECT qrySplit.City, SUM(qrySplit.["Orders <= 500"]), SUM(qrySplit.["Orders > 500"])
     FROM qrySplit
     GROUP BY qrySplit.City;

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 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

20 Experts available now in Live!

Get 1:1 Help Now