Author |
Topic |
darbar
Starting Member
16 Posts |
Posted - 2013-08-08 : 13:41:14
|
Outer query: select op.const_cd, (select const_hin from constituency c where c.const_cd=op.const_cd)from PollingStation op, constituency cwhere op.const_cd=c.const_cdgroup by op.const_cdorder by op.const_cdResult is:122 a 205123 b 205124 c 235125 d 191126 e 226127 f 159128 g 165129 h 175130 i 225131 j 213Inner Query result of: select const_cd, count(polling_cd) from PollingStation p where right(polling_cd,1)='A' group by p.const_cd order by p.const_cd:122 4123 4124 2125 3126 1127 6128 11129 9130 2I want this output:const_cd const_name count inner query122 a 205 4123 b 205 4124 c 235 2125 d 191 3126 e 226 1127 f 159 6128 g 165 11129 h 175 9130 i 225 2131 j 213 Please help me.Thanks in advance.Looking forward to receive jet help.  |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-08-08 : 13:59:12
|
Try this:[CODE]SELECT T1.const_cd, Const_Name, T2.[Count]FROM (select op.const_cd, (select const_hin from constituency c where c.const_cd = op.const_cd) as Const_Name from PollingStation op, constituency c where op.const_cd = c.const_cd group by op.const_cd order by op.const_cd) T1 LEFT JOIN (select const_cd, count(polling_cd) as [Count] from PollingStation p where right(polling_cd, 1) = 'A' group by p.const_cd order by p.const_cd) T2 ON T1.const_cd = T2.const_cd[/CODE] |
 |
|
darbar
Starting Member
16 Posts |
Posted - 2013-08-08 : 14:07:16
|
Thanks for your reply. but still I am getting this error:Msg 1033, Level 15, State 1, Line 17The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.Msg 156, Level 15, State 1, Line 26Incorrect syntax near the keyword 'order'. |
 |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-08-08 : 14:16:51
|
My bad:Try this:[CODE]SELECT T1.const_cd, Const_Name, T2.[Count]FROM (select op.const_cd, (select const_hin from constituency c where c.const_cd = op.const_cd) as Const_Name from PollingStation op, constituency c where op.const_cd = c.const_cd group by op.const_cd) T1 LEFT JOIN (select const_cd, count(polling_cd) as [Count] from PollingStation p where right(polling_cd, 1) = 'A' group by p.const_cd) T2 ON T1.const_cd = T2.const_cdorder by T1.const_cd[/CODE] |
 |
|
darbar
Starting Member
16 Posts |
Posted - 2013-08-08 : 14:18:58
|
Thanks bro. Its working fine. How can I use count() and sum() in addition to existing query. |
 |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-08-08 : 14:24:24
|
What do you want to sum() or count()? |
 |
|
darbar
Starting Member
16 Posts |
Posted - 2013-08-08 : 22:13:22
|
I want Sum() |
 |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-08-08 : 23:35:01
|
sum() based on which column? explain us the purpose too..--Chandu |
 |
|
darbar
Starting Member
16 Posts |
Posted - 2013-08-09 : 07:09:35
|
I need sum(). The other fields are totalmale, totalfemale, totalvalid etc. I want to use computed field submission too mainly totalmale, totalfemale |
 |
|
|