|
|
Archives of the TeradataForum
Message Posted: Tue, 02 May 2006 @ 13:37:16 GMT
Subj: | | Re: Need Help Writing SQL |
|
From: | | Anomy Anom |
<-- Anonymously Posted: Tuesday, May 02, 2006 09:14 -->
| As you can see I take col3 as col4 in the case I have an unique value for col1 and not the count (distinct). | |
Your suggestion would have worked if there were only 2 possible values in col4, a '1' when all the col3 values for a given col1 value were
unique (count distinct col3 = 1) and an '8' when col3 had different values for a given col1 value (count distinct col3 > 1). However, a third
value is required for col4, a '2' when all col3 values = 2 for a given col1 value - in your solution this would get incorrectly populated with a
'1' (as count distinct col3 = 1) ... so, using my initial illustration, col4 should be populated as follows:
col1 col1 col3 col4
Grp1 123 222 1 8
123 333 2 8
123 444 1 8
Grp2 234 555 1 1
234 666 1 1
234 777 1 1
Grp3 345 888 2 2
345 999 2 2
345 111 2 2
Best Regards
| |