|
|
-
Need help with simple subquery
shan s 2012-05-28, 13:48
I need help with a simple subquery. Given below data, I need counts and percentage counts per category. (Re-phrasing my earlier question ) With the code below I get an error: *FAILED: Parse Error:* line 6:50 *mismatched input ','* *expecting EOF near 'a'*
Looking at the documentation the syntax it is not clear to me.. In the form clause, can I have multiple selects and just alias them and use them in the top query? If so, what am I missing in the below code...
select a.category, a.count, b.totalCount from (select category, count(*) as count from gt group by category) a, (select count(*) as totalCount from gt) b ;
Many Thanks, Prashant.
Id Category Count Output Percentage Output 1 A A 4 A 40 (4/10)*100 2 A B 3 B 30 3 B C 3 C 30 4 A 5 C 6 C 7 B 8 B 9 A 10 C
-
Re: Need help with simple subquery
Igor Tatarinov 2012-05-28, 22:28
Try replacing the comma with JOIN
igor decide.com
On Mon, May 28, 2012 at 6:48 AM, shan s <[EMAIL PROTECTED]> wrote:
> I need help with a simple subquery. Given below data, I need counts and > percentage counts per category. (Re-phrasing my earlier question ) > With the code below I get an error: *FAILED: Parse Error:* line 6:50 *mismatched > input ','* *expecting EOF near 'a'* > > Looking at the documentation the syntax it is not clear to me.. In the > form clause, can I have multiple selects and just alias them and use them > in the top query? > If so, what am I missing in the below code... > > select a.category, a.count, b.totalCount > from > (select category, count(*) as count from gt group by category) a, > (select count(*) as totalCount from gt) b ; > > Many Thanks, > Prashant. > > Id Category Count Output Percentage Output > 1 A A 4 A 40 (4/10)*100 > 2 A B 3 B 30 > 3 B C 3 C 30 > 4 A > 5 C > 6 C > 7 B > 8 B > 9 A > 10 C >
-
Re: Need help with simple subquery
Nanda Vijaydev 2012-05-29, 18:25
Use a join as given below, I have used the table name temp.
select a.Category, a.count, b.tot_count, (100*a.count)/tot_count as percent_count from ( select Category, count(*) as count from temp group by Category ) a join (select count(*) as tot_count from temp) b on (true)
Hope this helps Nanda Vijaydev
On Mon, May 28, 2012 at 3:28 PM, Igor Tatarinov <[EMAIL PROTECTED]> wrote:
> Try replacing the comma with JOIN > > igor > decide.com > > On Mon, May 28, 2012 at 6:48 AM, shan s <[EMAIL PROTECTED]> wrote: > >> I need help with a simple subquery. Given below data, I need counts and >> percentage counts per category. (Re-phrasing my earlier question ) >> With the code below I get an error: *FAILED: Parse Error:* line 6:50 *mismatched >> input ','* *expecting EOF near 'a'* >> >> Looking at the documentation the syntax it is not clear to me.. In the >> form clause, can I have multiple selects and just alias them and use them >> in the top query? >> If so, what am I missing in the below code... >> >> select a.category, a.count, b.totalCount >> from >> (select category, count(*) as count from gt group by category) a, >> (select count(*) as totalCount from gt) b ; >> >> Many Thanks, >> Prashant. >> >> Id Category Count Output Percentage Output >> 1 A A 4 A 40 (4/10)*100 >> 2 A B 3 B 30 >> 3 B C 3 C 30 >> 4 A >> 5 C >> 6 C >> 7 B >> 8 B >> 9 A >> 10 C >> > >
-
Re: Need help with simple subquery
shan s 2012-06-04, 12:39
Thanks Nanda, Igor, This worked..
On Tue, May 29, 2012 at 11:55 PM, Nanda Vijaydev <[EMAIL PROTECTED]>wrote:
> Use a join as given below, I have used the table name temp. > > select a.Category, a.count, b.tot_count, (100*a.count)/tot_count as > percent_count > from ( select Category, count(*) as count from temp group by Category ) > a > join (select count(*) as tot_count from temp) b > on (true) > > Hope this helps > Nanda Vijaydev > > > On Mon, May 28, 2012 at 3:28 PM, Igor Tatarinov <[EMAIL PROTECTED]> wrote: > >> Try replacing the comma with JOIN >> >> igor >> decide.com >> >> On Mon, May 28, 2012 at 6:48 AM, shan s <[EMAIL PROTECTED]> wrote: >> >>> I need help with a simple subquery. Given below data, I need counts and >>> percentage counts per category. (Re-phrasing my earlier question ) >>> With the code below I get an error: *FAILED: Parse Error:* line 6:50 *mismatched >>> input ','* *expecting EOF near 'a'* >>> >>> Looking at the documentation the syntax it is not clear to me.. In the >>> form clause, can I have multiple selects and just alias them and use them >>> in the top query? >>> If so, what am I missing in the below code... >>> >>> select a.category, a.count, b.totalCount >>> from >>> (select category, count(*) as count from gt group by category) a, >>> (select count(*) as totalCount from gt) b ; >>> >>> Many Thanks, >>> Prashant. >>> >>> Id Category Count Output Percentage Output >>> 1 A A 4 A 40 (4/10)*100 >>> 2 A B 3 B 30 >>> 3 B C 3 C 30 >>> 4 A >>> 5 C >>> 6 C >>> 7 B >>> 8 B >>> 9 A >>> 10 C >>> >> >> >
|
|