Many times we get requirement to show the values which are in the same row having different values in the different columns.
Below example can help you on this....
1. Below is the Item price details table, having price for different items for different seller under different currency.
2. The requirement is to display the price of each item based on the seller and currency in a single row as shown below.
3. For this requirement, we could use the MAX function to get the result in simple query.
Below is the query to be used for it.
SELECT item,
MAX(DECODE(seller||currency , 'SELLER1USD', price, '')) "SELLER1-USD",
MAX(DECODE(seller||currency , 'SELLER1EUR', price, '')) "SELLER1-EUR",
MAX(DECODE(seller||currency , 'SELLER1INR', price, '')) "SELLER1-INR",
MAX(DECODE(seller||currency , 'SELLER2USD', price, '')) "SELLER2-USD",
MAX(DECODE(seller||currency , 'SELLER2EUR', price, '')) "SELLER2-EUR",
MAX(DECODE(seller||currency , 'SELLER2INR', price, '')) "SELLER2-INR"
FROM xxpet_item_price_details
GROUP BY item
ORDER BY item
Thanks and Regards,
Peter Amal Raj
Below example can help you on this....
1. Below is the Item price details table, having price for different items for different seller under different currency.
2. The requirement is to display the price of each item based on the seller and currency in a single row as shown below.
3. For this requirement, we could use the MAX function to get the result in simple query.
Below is the query to be used for it.
SELECT item,
MAX(DECODE(seller||currency , 'SELLER1USD', price, '')) "SELLER1-USD",
MAX(DECODE(seller||currency , 'SELLER1EUR', price, '')) "SELLER1-EUR",
MAX(DECODE(seller||currency , 'SELLER1INR', price, '')) "SELLER1-INR",
MAX(DECODE(seller||currency , 'SELLER2USD', price, '')) "SELLER2-USD",
MAX(DECODE(seller||currency , 'SELLER2EUR', price, '')) "SELLER2-EUR",
MAX(DECODE(seller||currency , 'SELLER2INR', price, '')) "SELLER2-INR"
FROM xxpet_item_price_details
GROUP BY item
ORDER BY item
Thanks and Regards,
Peter Amal Raj
No comments:
Post a Comment