[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How would modify a query to group by a field and within each grouping, have an order by clause?

Posted on 2014-01-10
5
Medium Priority
?
320 Views
Last Modified: 2014-01-10
I am working with a query using Access 2003.

How would you modify the following query to order the records by
 [Age(Days)] DESC within tblBanks.[Senior Management

In other words I want to group records by the field tblBanks.[Senior Management
and withinin each grouping, the records should be sorted in [Age(Days)] DESC.


SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("A","D","E");
UNION ALL
SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("B","C")
ORDER BY [Age(Days)] DESC;
0
Comment
Question by:zimmer9
[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
  • 3
5 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39772206
try this


select x.*
From
(SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("A","D","E");
UNION ALL
SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("B","C")
) As X
Order By x.[Age(Days)] Desc


or use use this Order bY

Order By 11 DESC
0
 
LVL 39

Expert Comment

by:PatHartman
ID: 39772531
ORDER BY [Senior Management Tab], [Age(Days)] DESC

OR

ORDER BY [Senior Management Tab] ASC, [Age(Days)] DESC
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39772565
oops sorry, forgot about the Management group


select x.*
From
(SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("A","D","E");
UNION ALL
SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("B","C")
) As X
Order By X.[Senior Management Tab], x.[Age(Days)] Desc




.
0
 

Author Comment

by:zimmer9
ID: 39772593
Please see attached doc. Thank you.
Synax.doc
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 39772633
remove the semi colon  from this line

Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("A","D","E"); '<<<<
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

650 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