Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 18 Oct 2007 @ 13:22:50 GMT


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


Subj:   Re: Conditionally Converting a Many to One relationship
 
From:   Anomy Anom

<-- Anonymously Posted: Thu, 18 Oct 2007 08:14:31 -->

If there is a relatively small, known set of Attribute_IDs then something like the following should work:

     SELECT ITEM_ID,
     CASE
       WHEN ATTRIBUTE_FLAG_1 = 0
        AND ATTRIBUTE_FLAG_2 = 1
        AND ATTRIBUTE_FLAG_3 = 1 THEN 4

       WHEN ATTRIBUTE_FLAG_1 = 1
        AND ATTRIBUTE_FLAG_2 = 0
        AND ATTRIBUTE_FLAG_3 = 0 THEN 5

       ELSE 6

     END AS ITEM_SUMMARY_FLAG

     FROM (SELECT ITEM_ID,
     MAX(CASE WHEN ITEM_ATTRIBUTE = 1 THEN 1 ELSE 0 END) AS ATTRIBUTE_FLAG_1,
     MAX(CASE WHEN ITEM_ATTRIBUTE = 2 THEN 1 ELSE 0 END) AS ATTRIBUTE_FLAG_2,
     MAX(CASE WHEN ITEM_ATTRIBUTE = 3 THEN 1 ELSE 0 END) AS ATTRIBUTE_FLAG_3
     FROM TheOriginalTable GROUP BY 1) D_T_E;


     
  <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