|
|
Archives of the TeradataForum
Message Posted: Thu, 18 Oct 2007 @ 12:18:39 GMT
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
| |