473,480 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Order by an aggregate function

I can't seem to get the following SQL statement with the ORDER BY clause to
work. It does work if I order by any of the fields in the SELECT part of the
statement but not if it is the field in the TRANSFORM part.
The posted code is from the Immediate Pane:

TRANSFORM Format(Sum([TEMPTABLEA].ELEC_EUI),'#,###.00') AS EUI SELECT
BUILDING_TYPE As Type, [TEMPTABLEA].BUILDING_TYPE_DESC As Description FROM
[TEMPTABLEA] GROUP BY [TEMPTABLEA].BUILDING_TYPE, [TEMPTABLEA].
BUILDING_TYPE_DESC ORDER BY Format(Sum([TEMPTABLEA].ELEC_EUI),'#,###.00') ASC
PIVOT [TEMPTABLEA].CITY

The error is that I can't have an aggregate function in the ORDER BY Clause.
I tried using the alias, EUI, but that doesn't work either. So how do I
order by this.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200607/1
Jul 25 '06 #1
2 8384
DFS
rdemyan via AccessMonster.com wrote:
I can't seem to get the following SQL statement with the ORDER BY
clause to work. It does work if I order by any of the fields in the
SELECT part of the statement but not if it is the field in the
TRANSFORM part.
The posted code is from the Immediate Pane:

TRANSFORM Format(Sum([TEMPTABLEA].ELEC_EUI),'#,###.00') AS EUI SELECT
BUILDING_TYPE As Type, [TEMPTABLEA].BUILDING_TYPE_DESC As Description
FROM [TEMPTABLEA] GROUP BY [TEMPTABLEA].BUILDING_TYPE, [TEMPTABLEA].
BUILDING_TYPE_DESC ORDER BY
Format(Sum([TEMPTABLEA].ELEC_EUI),'#,###.00') ASC PIVOT
[TEMPTABLEA].CITY

The error is that I can't have an aggregate function in the ORDER BY
Clause. I tried using the alias, EUI, but that doesn't work either.
So how do I order by this.
You can't, because it doesn't make sense to ORDER BY anything being
TRANSFORMed in a crosstab.

The MS warning should say something about this explicitly, because you
actually can have an agg function in the ORDER BY statement of a
non-crosstab query, ie:

SELECT BUILDING_TYPE_DESC As Description, Format(Sum(ELEC_EUI),'#,###.00')
as EUI
FROM TEMPTABLEA
GROUP BY BUILDING_TYPE_DESC
ORDER BY Format(Sum(ELEC_EUI),'#,###.00') DESC


Jul 25 '06 #2
The ORDER BY clause has to refer to one of the fields that is a Row Heading
in the crosstab.

In any case, the Format() function outputs Text, so it would not sort
numeric values correctly. You could avoid that by creating the query without
the Format(). Then set the Format() property of the field (properties box in
query design view.)

Your query statement will be something like this:
TRANSFORM Sum(ELEC_EUI)
SELECT BUILDING_TYPE, BUILDING_TYPE_DESC
FROM TEMPTABLEA
GROUP BY BUILDING_TYPE, BUILDING_TYPE_DESC
ORDER BY BUILDING_TYPE
PIVOT CITY;

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"rdemyan via AccessMonster.com" <u6836@uwewrote in message
news:63c22277637d3@uwe...
>I can't seem to get the following SQL statement with the ORDER BY clause to
work. It does work if I order by any of the fields in the SELECT part of
the
statement but not if it is the field in the TRANSFORM part.
The posted code is from the Immediate Pane:

TRANSFORM Format(Sum([TEMPTABLEA].ELEC_EUI),'#,###.00') AS EUI SELECT
BUILDING_TYPE As Type, [TEMPTABLEA].BUILDING_TYPE_DESC As Description FROM
[TEMPTABLEA] GROUP BY [TEMPTABLEA].BUILDING_TYPE, [TEMPTABLEA].
BUILDING_TYPE_DESC ORDER BY Format(Sum([TEMPTABLEA].ELEC_EUI),'#,###.00')
ASC
PIVOT [TEMPTABLEA].CITY

The error is that I can't have an aggregate function in the ORDER BY
Clause.
I tried using the alias, EUI, but that doesn't work either. So how do I
order by this.

Jul 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2238
by: sausage31 | last post by:
I have a table as follows.... Device LotID Result1 Result2 Result3 aaa 1 5 10 15 bbb 1 2 4 6 aaa 2 ...
1
14466
by: nfrodsham | last post by:
In Microsoft's help literature, it states: "You can filter out non-unique rows by using the DISTINCT option of an aggregate function" I am trying to do this in Access 2003 with the COUNT...
10
11901
by: neb | last post by:
Dear member of the forum, Ms access has built-in aggregate function like: -Sum, Max, First, Avg, ... Is it possible to build user-defined aggregate? (if you have any clue, do not hesitate to...
1
2705
by: Najib Abi Fadel | last post by:
Hi i have an ordered table of dates let's say: 1/1/2004 8/1/2004 15/1/2004 29/1/2004 5/2/2004 12/2/2004
3
4137
by: beconrad | last post by:
Hi all, I am not sure if what I want to do is possible, and if it is I have not been able to figure out how to do it. This is what I would like: 1. I have a data entry form with a field...
0
1424
by: Conrad | last post by:
Greetings, For user actions on a wxWidget that trigger multiple events for that wxWidget, is the order those events are processed in undefined, and therefore arbitrary from one platform (ie...
0
1567
by: BillCo | last post by:
just wasted a long time figuring out this and I figure if I post it might save someone some pain! Jet (DAO) will allow you to to use nested aggregate functions like building blocks, e.g.: ...
5
6077
by: BillCo | last post by:
I just wasted a long time figuring out this and I figure if I post it might save someone some pain! Jet (DAO) will allow you to to use nested aggregate functions like building blocks, e.g.: ...
2
6086
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
0
7044
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7087
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4483
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.