If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > case and MAX

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-25-07, 08:20
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
 
Join Date: Jan 2005
Posts: 75
case and MAX

what is the wrong with this????

Code:
MAX (CASE WHEN MAX (X1)=val1 THEN X2
ELSE WHEN MAX (Y1)=val2 THEN Y2) AS XXXX  )

Last edited by ahmedwaseem2000; 05-25-07 at 08:30.
Reply With Quote
  #2 (permalink)  
Old 05-25-07, 08:32
baloo99 baloo99 is offline
Registered User
 
Join Date: Feb 2007
Location: Bratislava, Slovakia
Posts: 85
several tips:
-- missing END
-- SHIP-VIOL-D-Q - instead '-' use '_'
instead max(x1) use subselect

or paste whole select
Reply With Quote
  #3 (permalink)  
Old 05-25-07, 13:30
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
There are several semantical and syntactical problems:
- Have a look at the syntax diagram for CASE expressions, first. The construct "ELSE WHEN" is not right at all.
- What should the result be if the equality comparisons are both not met or just one is not met?
- What is the nested MAX(X1) and MAX(Y1) supposed to be doing? They need a table and a column to operate on. Both compute the maximum of all the values in column X1 and Y1, respectively. Then you throw things off because a CASE expression operates on a single row only - not a table.

Maybe you want to do this:
Code:
WITH t1(max_x1, max_y1) AS
   ( SELECT MAX(x1), MAX(y1)
     FROM ... ),
t2 (val) AS 
   ( SELECT CASE
               WHEN max_x1 = val1 THEN x2
               WHEN max_y1 = val2 THEN y2
               ELSE NULL
            END
     FROM   t1 )
SELECT MAX(val)
FROM   t2
I think this is much clearer. The rest is the optimizer's job to do something useful with it and come up with the best access plan.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On