View previous topic :: View next topic
|
Author |
Message |
rahuindo
New User
Joined: 09 Apr 2008 Posts: 83 Location: Chennai
|
|
|
|
Hi,
I have the a DB2 table PROD-RULE-CD which has the following columns:
Company-ID
Product-ID
State-Cd
Category-Cd
Rule-Cd
A sample data in the table is as follows:
Code: |
COMP_ID PROD_ID ST_CD CAT_CD RULE_CD
=========================================
01 141 AK A 2006
01 141 AK R 0516
01 141 AL A 2006
01 141 AL R 0516
01 141 AZ A 2001
01 141 AZ S 0063
01 141 AZ R 0516
01 141 CA A 2001
01 141 CA A 2006
01 141 CA R 0516 |
In this table, I have a Company-ID and Product ID available in each state and a rule-cd applies to the Company-Code and Product ID in that state.
Now, I want to find out the unique Rule-CD combinations which are present in this table.
So, in the above data sample, the State of AK and AL has the same Rule-CD combinations i.e. the Rule Code 2001 and 0516 apply to both the states. AZ and CA have a different rule-cd combinations. For AZ, the rule-cd which can be applied is 2001, 0063 and 0516. For CA, the rule-cd is 2001, 2006 and 0516.
Can I find out the unique combinations in a query? I tried ranking but that does not work. |
|
Back to top |
|
|
Gary McDowell
Active User
Joined: 15 Oct 2012 Posts: 139 Location: USA
|
|
|
|
Some form of...
SELECT DISTINCT row_name
may help.?. |
|
Back to top |
|
|
rahuindo
New User
Joined: 09 Apr 2008 Posts: 83 Location: Chennai
|
|
|
|
Hi Gary,
Distinct does not work because each row is distinct so it returns all the rows. I do have a logic to implement in COBOL but just checking if anyone in forum have some idea to implement in DB2 query. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Could you please let me know the expected output with code tags on? |
|
Back to top |
|
|
|