Solved

Help with Query in access

Posted on 2013-11-01
2
137 Views
Last Modified: 2013-11-21
I have  table
Grouping      Indicator      Count      CountContracts      Savings
Status A      #      4      7                     1.3
Status A      X      7      10                     3.8
Status B      #      8      2                     6
Status B      X      5      1                     0.5
Status C      #      6      3                     21.75
Status C      X      6      5                     4.092


I need a query which should give me the number of :

Count for Status A and B only, Saving for A and B only, Count for # for A and B only, Saving for # for A and B only
It should be :
24,     11.6,           9,          7.3
0
Comment
Question by:rfedorov
2 Comments
 
LVL 40

Accepted Solution

by:
Sharath earned 400 total points
ID: 39618067
try this.
SELECT SUM([Count]) AS AB_Count,
       SUM([Savings]) AS AB_Savings,
	   SUM(IIF([Indicator] = '#',[CountContracts],0)) AS [AB#_CountContracts],
	   SUM(IIF([Indicator] = '#',[Savings],0)) AS [AB#_Savings]
  FROM your_table
 WHERE [Grouping] IN ('Status A','Status B')

Open in new window

0
 
LVL 39

Assisted Solution

by:als315
als315 earned 100 total points
ID: 39618618
You can also add some table, where your groups will be combined to supergroups. For your sample it will be:
Grouping           SuperGroup
Status A              SuperG1
Status B              SuperG1
Status C              SuperG2
Add this table to your query and you will be able to filter by this supergroup. It is very helpful if you use pivot tables.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

21 Experts available now in Live!

Get 1:1 Help Now