with Questions - TeradataQuestions most recent 30 from http://teradataquestions.com 2010-09-09T15:43:34Z http://teradataquestions.com/feeds/tag/with http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://teradataquestions.com/questions/68/decode-with-rownum Decode with Rownum TDHelp 2010-01-26T20:31:10Z 2010-01-28T12:18:35Z <p>Hi,</p> <p>I have a requirement in Oracle using Decode function with Rownum. I need to convert this into Teradata. I need help in this. I tried using Top function and Rank qualify but unable to do the same. Please help me in this.</p> <p>sample query in Oracle is:</p> <pre><code>SELECT DECODE(ROWNUM, 1, party, 2, party, 3, party, 4, party, 5, party,6, party, 7,party,'Others') party, mnth,SUM(qty) FROM ( SELECT NVL(trim(b.Party_name),'Others') party, c.MONTH_ID mnth, SUM(a.qty) qty FROM tablea a,tableb b,tablec c WHERE a.col1 = b.col1 AND a.col2 = c.col1 AND a.col3='Y' GROUP BY party,mnth ORDER BY SUM(a.qty) DESC ) GROUP BY DECODE(ROWNUM, 1, party, 2, party, 3, party, 4, party, 5, party, 6, party, 7, party, 'Others'),mnth </code></pre> <p>Please help me the conversion of outer query in Teradata. Thanks in Advance.</p> <p>Thanks and Regards, TDHelp.</p>