?
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
?
319 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 38

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…
Suggested Courses

771 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