Solved

Difficult  SQL  QUERY

Posted on 1998-08-06
2
210 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
[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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

697 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