473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem with a query with MAX function

I have this query:
SELECT AGG_NAME, MAX(AGG_RELNUM) RELNUM, MAX(AGG_RELSPEC) RELSPEC, MAX(ED)
EDIZ

FROM
(SELECT .....
) AT GROUP BY AGG_NAME

The problem that the query reply records in which the values is different
from the value in tables. My query is correct???
Is possible to use three MAX in the same query??

Thank you
Nov 12 '05 #1
1 3533
Nicole wrote:
I have this query:
SELECT AGG_NAME, MAX(AGG_RELNUM) RELNUM, MAX(AGG_RELSPEC) RELSPEC, MAX(ED)
EDIZ

FROM
(SELECT .....
) AT GROUP BY AGG_NAME

The problem that the query reply records in which the values is different
from the value in tables. My query is correct??? You curent query has 3 independent MAX() functions. That is, while
every values RELNUM, RELSPEC and EDIZ was coming ultimately in query
below the row (AGGNAME, RELNUM, RELSPEC, EDIZ) may not exist.
To answer the request:
"Give me the rows AGG_NAME for which AGG_RELNUM, .. is maximum!"
you need OLAP:
SELECT AGGNAME, AGG_RELNUM, AGG_RELSPEC, ED
FROM
(SELECT ROW_NUMBER()
OVER(PARTITION BY AGGNAME
ORDER BY AGG_RELNUM DESC, AGG_RELSPEC DESC, ED
DESC) AS rn,
AGG_NAME, AGG_RELNUM, AGG_RELSPEC, ED
FROM (....) AS T) AS S
WHERE rn = 1;

(you can add/remove elements to the PARTITIONIN BY and the ORDER BY
clause as required for your semantics.
Is possible to use three MAX in the same query?? Yes, absolutely
Thank you

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2

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

Similar topics

5
by: Juho Saarikko | last post by:
I made a Python script which takes Usenet message bodies from a database, decodes uuencoded contents and inserts them as Large Object into a PostGreSQL database. However, it appears that the to...
1
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 ...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
3
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using...
12
by: Joel Byrd | last post by:
I'm having a little problem with using type-ahead functionality for an auto-suggest box. Sometimes, when I start to type something and the type-ahead shows up, the AJAX will send a request query...
8
by: Gox | last post by:
Hi, I got a problem with VBE6.DLL (VBA reference) On my machine everything work well.(access 2k, vesion dll 6.0.84.35) First machine NO PROBLEM (access 2003, vesion dll 6.4.99.72) Second machine...
6
by: mforema | last post by:
Hi Everybody, I have a function that worked perfectly when it was used in a query. I received help in creating this function from this discussion: Help with Query and Subform - post #18 ...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
6
by: fido19 | last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp). Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha was tall and handsome –...
1
by: giovannino | last post by:
Dear all, I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !). 1) Given that I'm not a programmer I can't understand why...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.