Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 18 Oct 2007 @ 12:18:39 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Conditionally Converting a Many to One relationship
 
From:   Kamin Shah

Mathew,

Would this work for you? This is specific to the example you gave below.

     SELECT MIN_TBL.ITEM_ID,
     CASE
     WHEN MIN_VAL = 2 AND MAX_VAL=3
     THEN 4
     WHEN MIN_VAL = 1 AND MAX_VAL = 1
     THEN 5
     ELSE 6
     END AS NEW_VAL
     FROM
     (
     SELECT
     ITEM_ID,
     MIN(ITEM_ATTR) AS MIN_VAL
     FROM ITEM
     GROUP BY 1
     ) MIN_TBL
     INNER JOIN
     (
     SELECT
     ITEM_ID,
     MAX(ITEM_ATTR) AS MAX_VAL
     FROM ITEM
     GROUP BY 1
     ) MAX_TBL
     ON MIN_TBL.ITEM_ID = MAX_TBL.ITEM_ID;

Kamin Shah



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023