473,466 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

order query on set function

aas4mis
97 New Member
I have a query that works fine when ordered by the puller id (cf.op.id). The problem comes when I try to order by the sum of the boxes (sum(cf.qq)).

I have read "UniVerse SQL Reference" and "UniVerse SQL User Guide". I don't see any way possible to display the results the way I want.

This is my working query.
Expand|Select|Wrap|Line Numbers
  1. SELECT                                   
  2. SQL+CF.OP.ID, SUM(CF.QQ)                  
  3. SQL+FROM UNNEST PICK.TRANS.HDC ON CF.OP.ID
  4. SQL+WHERE CF.QQ > 0                       
  5. SQL+GROUP BY CF.OP.ID;  
  6.  
My Results.
Expand|Select|Wrap|Line Numbers
  1. Cf.op.id SUM ( CF.QQ )
  2. AAM                  4
  3. ABC                  1
  4. ADB                 56
  5. ADD                  2
  6. ADH                  2
  7.  
My Desired Results
Expand|Select|Wrap|Line Numbers
  1. Cf.op.id SUM ( CF.QQ )
  2. ADB                  56
  3. AAM                  4
  4. ADD                  2
  5. ADH                  2
  6. ABC                  1
  7.  
Does anybody know how to group by sum(cf.qq) and get the desired results?
May 29 '08 #1
2 2096
docdiesel
297 Recognized Expert Contributor
Hi,

Expand|Select|Wrap|Line Numbers
  1. SELECT                                   
  2.   CF.OP.ID,
  3.   SUM(CF.QQ) as SUM_CF_QQ
  4. FROM
  5.   UNNEST PICK.TRANS.HDC ON CF.OP.ID
  6. WHERE
  7.   CF.QQ > 0                       
  8. GROUP BY
  9.   CF.OP.ID
  10. ORDER BY
  11.   SUM(CF.QQ) DESC
  12. ;
should do the job.

Regards,

Bernd
May 30 '08 #2
aas4mis
97 New Member
Hi,

Expand|Select|Wrap|Line Numbers
  1. SELECT                                   
  2.   CF.OP.ID,
  3.   SUM(CF.QQ) as SUM_CF_QQ
  4. FROM
  5.   UNNEST PICK.TRANS.HDC ON CF.OP.ID
  6. WHERE
  7.   CF.QQ > 0                       
  8. GROUP BY
  9.   CF.OP.ID
  10. ORDER BY
  11.   SUM(CF.QQ) DESC
  12. ;
should do the job.

Regards,

Bernd

Thanks, I literally spent an entire work day on this query researching what I was doing wrong. I should've came here a lot sooner, I always find an answer here. I did have to change the order by clause, it was throwing a syntax error "unexpected verb SUM". The following code worked perfectly.

Expand|Select|Wrap|Line Numbers
  1. >SELECT                                                        
  2. SQL+MIN(CF.DT) AS "FIRST CF", CF.OP.ID, SUM(CF.QQ) AS SUM_CF_QQ
  3. SQL+FROM UNNEST PICK.TRANS.HDC ON CF.OP.ID                     
  4. SQL+WHERE CF.QQ > 0                                            
  5. SQL+GROUP BY CF.OP.ID                                          
  6. SQL+ORDER BY SUM_CF_QQ DESC;                                   
  7.  
Thanks for all your help!
May 30 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Deborah V. Gardner | last post by:
I have a field with values like this CO 03-10 CO 03-4 VI 03-8 CO 03-533 I would like these to sort for a report by the first two letters and the digits after the hyphen (-) like this
5
by: Ataru Morooka | last post by:
Hi, my table has to have a column with the months names (january, february...). When I order it by month it is ordered alphabetically and that's not what I need. Reading this ng I found someone...
22
by: Nhmiller | last post by:
Is there a way to do this? Thanks. Neil Cat Paintings At Carol Wilson Gallery http://www.carolwilsongallery.com
8
by: Jernej Kos | last post by:
I have a multicolumn index on two columns. If i use the columns in ORDER BY like this: ORDER BY col1, col2; The index is used. But, if one column is sorted DESC it is not used: ORDER BY col1...
104
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through...
3
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...
13
by: bevanward | last post by:
Hi All I am finding unexpected results when inserted into a newly created table that has a field of datatype int identity (1,1). Basically the order I sort on when inserting into the table is...
2
by: rdemyan via AccessMonster.com | last post by:
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...
3
by: Beowulf | last post by:
I was just messing around with some ad hoc views and table returning UDFs today so I could look at and print out data from a small table and noticed something strange. If I stick my select...
6
by: InnoCreate | last post by:
Hi everyone. I've recently written a classic asp website which uses an MS Access datasource. I know this is less than an ideal data source as it has limited functionality. I have a search form on...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.