﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Teradata Forums / Teradata  / Teradata Database  / Select clause inside fields list / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>Teradata Forums</description><link>http://www.teradata.com/teradataforum/</link><webMaster>info@teradata.com</webMaster><lastBuildDate>Sat, 21 Nov 2009 19:17:19 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Select clause inside fields list</title><link>http://www.teradata.com/teradataforum/Topic16031-9-1.aspx</link><description>Hi Rodrigo.you can rewrite it using an OLAP function, too:SELECT ID_CDR, COUNT(*) AS QTD  ,CAST (QTD * 100 / sum(QTD) OVER () AS DEC(10, 2)) AS PercentFROM Table_1 GROUP BY ID_CDRQUALIFY ROW_NUMBER() OVER ( ORDER BY QTD DESC) &amp;lt;= 3Depending on your needs, you might replace ROW_NUMBER with a faster RANK, this will return a TOP WITH TIES.Dieter</description><pubDate>Sun, 05 Jul 2009 10:35:21 GMT</pubDate><dc:creator>dnoeth</dc:creator></item><item><title>RE: Select clause inside fields list</title><link>http://www.teradata.com/teradataforum/Topic16031-9-1.aspx</link><description>Rob Paller, I appreciate your reply!I still didn't have the chance to try your query in tera data 'cause my server is currently under maintenance... Too bad =/Well, I liked your idea and I can't see why it shouldn't work. I'll let you know if anything fail.Thank you so much!Regards,Rodrigo.</description><pubDate>Sun, 05 Jul 2009 09:38:48 GMT</pubDate><dc:creator>digo</dc:creator></item><item><title>RE: Select clause inside fields list</title><link>http://www.teradata.com/teradataforum/Topic16031-9-1.aspx</link><description>I don't believe until TD13 can you embed a SELECT statement within a column, which is similar to what Oracle permits currently. Try a CROSS JOIN instead. Since it will only return a single row the penalty for the product join is minimal and should not cause you any problems.SELECT TOP 3         ID_1      , QTD      , CAST (Cast( (QTD * 100) AS NUMERIC) / Denominator.MyCountAS DEC(10, 2)) AS PercentFROM ( SELECT ID_1, COUNT(*) AS QTD FROM Table_1 GROUP BY ID_CDR) AS MyTableCROSS JOIN(SELECT COUNT(*) AS MyCount FROM Table_1) AS DenominatorORDER BY Percent DESC</description><pubDate>Sat, 04 Jul 2009 20:21:23 GMT</pubDate><dc:creator>Rob Paller</dc:creator></item><item><title>Select clause inside fields list</title><link>http://www.teradata.com/teradataforum/Topic16031-9-1.aspx</link><description>I've been trying to run an SQL statement at TeraData and it keeps on failing...The error I receive is: "3706: Syntax error: expected something between '/' and the 'SELECT' keyword."The SQL statement is:"SELECT TOP 3 ID_1, QTD, CAST (			         Cast( (QTD * 100) AS NUMERIC)	/     SELECT COUNT(*) FROM Table_1                 AS DEC(10, 2)			        ) AS PercentFROM ( SELECT ID_1, COUNT(*) AS QTD  FROM Table_1 GROUP BY ID_CDR) AS MyTableORDER BY Percent DESC"As you may see in the query, there is a select inside the fields' list... Would that be the reason of the error? Can anyone help me?Regards.Rodrigo Duarte.</description><pubDate>Fri, 03 Jul 2009 14:26:31 GMT</pubDate><dc:creator>digo</dc:creator></item></channel></rss>