| Author |
Topic |
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2008-10-04 : 01:25:33
|
| I have to count data of all levelsplz help me :WITH CatTree ( Level,totalNo) AS ( SELECT 1 As [Level] , count(aid) As totalNo FROM members Level where isID = 'U100000000' UNION ALL SELECT Level + 1 ,count(aid)as totalNo FROM members where level<5 ) SELECT * FROM CatTree Order By Level it give me errors as:Msg 207, Level 16, State 1, Line 14Invalid column name 'level'.Msg 207, Level 16, State 1, Line 12Invalid column name 'Level'.Ved Prakash Jha |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-10-04 : 01:32:57
|
| Try thisWITH CatTree ( Level,totalNo)AS(SELECT 1 As [Level] , count(aid) As totalNoFROM members Levelwhere isID = 'U100000000'UNION ALLSELECT Level + 1 ,count(totalno)as totalNoFROM cattree where level<5 )SELECT * FROM CatTree Order By Level |
 |
|
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2008-10-04 : 02:13:42
|
| WITH CatTree ( Level,totalNo)AS(SELECT 1 As [Level] , count(aid) As totalNoFROM members Levelwhere isID = 'U100000000'UNION ALLSELECT Level + 1 ,count(totalno)as totalNoFROM cattreewhere level<5)SELECT * FROM CatTree Order By Levelits give me errors as:Msg 8120, Level 16, State 1, Line 2Column 'CatTree.Level' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Msg 467, Level 16, State 1, Line 2GROUP BY, HAVING, or aggregate functions are not allowed in the recursive part of a recursive common table expression 'CatTree'.Then I change my qyery as:WITH CatTree ( Level,totalNo)AS( SELECT 1 As [Level] , count(aid) As totalNo FROM members Level group by [Level] having isID = 'U100000000' UNION ALL SELECT Level + 1 ,count(totalno)as totalNo FROM cattree INNER JOIN CatTree ON CatTree.aid= C.isid group by Level+1 having level<5)SELECT * FROM CatTree Order By Leveleroor as:Msg 207, Level 16, State 1, Line 7Invalid column name 'Level'.Msg 253, Level 16, State 1, Line 7Recursive member of a common table expression 'CatTree' has multiple recursive references.Ved Prakash Jha |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-04 : 02:28:43
|
can you explain what you're trying to do inside CTE? is this what you want?;WITH CatTree ( Level,aid)AS(SELECT 1 As [Level] , aid FROM [members Level]where isID = 'U100000000'UNION ALLSELECT Level + 1 ,m.aid FROM [members Level] mINNER JOIN CatTree c ONC.aid= m.isid)SELECT Level,COUNT(aid)AS TotalNoFROM CatTree WHERE Level<5 GROUP BY Level |
 |
|
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2008-10-04 : 03:03:56
|
| I want to count total Data , Level wiseasI(ABC) have sponsor(>) A and BA >cB>DABC>eABC>fc>gd>h it will show for ABC asAbc a b e f Level1c d Level2 g h Level3Theb Result would be for ABC: Leve1=4 Leve2=2 Leve3=2Ved Prakash Jha |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-04 : 03:14:10
|
| doesnt my solution give same result? |
 |
|
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2008-10-04 : 03:18:20
|
| sorry.. Forget to tell one thing....whenever Any Person join company taking different Packages and having their Different PointsP1=1p2 =6p3=12asI want to count total Data , Level wiseasI(ABC) have sponsor(>) A (p1) and B(p1)A >c(p2)B>D(p3)ABC>e(p2)ABC>f(p1)c>g(1)d>h(p3)it will show for ABC asAbca b e f Level1c d Level2g h Level3Theb Result would be for ABC:Leve1=9Leve2=18Leve3=13Ved Prakash Jha |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-04 : 03:21:49
|
| show some sample data and output you expect out of them. your explanation doesnt make much sense. |
 |
|
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2008-10-04 : 03:38:46
|
| Package1=1 pointPackage2=6 pointPackage3=12 pointIf A Sponsor B with Package1A Sponsor C with Package3A Sponsor D with Package2A Sponsor E with Package1 B Sponsor F with Package1C Sponsor G with Package2D Sponsor H with Package3A;;;;;; B;C;D;E;;;;;;;;Level1F;G;H;;;;;;;;;;;;;;;Level2For A:Level1=20Level2=19for B: Level1=1For C: Level1=6For D: Level1=12Ved Prakash Jha |
 |
|
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2008-10-04 : 03:54:27
|
| please responseVed Prakash Jha |
 |
|
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2008-10-04 : 04:20:09
|
| In the previous Time I were asked about CTE,Problem is solved, but having different output means it is correct but i want it in no duplicacy in levels. Query is:;WITH CatTree ( Level,aid)AS( SELECT 1 As [Level] , aid FROM [members] where aid not like 'R%' and isID = 'U100000075' UNION ALL SELECT Level + 1 ,m.aid FROM [members] m INNER JOIN CatTree c ON C.aid= m.isid where m.aid not like 'R%' ) SELECT Level,(COUNT(aid)* p.iPoint) AS TotalNo FROM CatTree c1 join scratch s on c1.aid=s.vat_id join package p on s.vpackage=p.vpackage WHERE Level<=5 GROUP BY Level,p.ipointOutput is:1 42 133 764 2115 2803 124 425 722 123 604 485 204There is Duplicacy in levels I want remove that . it comes due to grpup by clause. If I write"GROUP BY Level,p.ipoint" instead of "GROUP BY Level" then it gives me error aserror:Msg 8120, Level 16, State 1, Line 2Column 'package.iPoint' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.plz help meVed Prakash Jha |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-04 : 06:51:32
|
| without seeing some sample data its really hard to understand how tables are related and what you're expecting as output. whats preventing you from posting data and output as repeatedly asked. Know how to post a question by refering below link.http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
|