Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
vinod.n.kobal
Starting Member
5 Posts |
Posted - 2011-05-10 : 07:54:04
|
hello,the table structure is as follows table name is educationedu_id|stid_id|qual_id|percentage|---------------------------------- 1 | 2 | 1 | 60 | 2 | 2 | 2 | 70 | 3 | 2 | 3 | 72 | 4 | 3 | 1 | 90 | 5 | 3 | 3 | 40 | 6 | 5 | 2 | 60 |now i want to find those student who scores the more than 60%now the fable field qual_id 1 is for 10th 2 is for 12th 3 for PG etc the each student has some qualification, now the problem is that i want such a query which display the student Id who scores the more than 60% in each respective class |
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-05-10 : 09:11:00
|
TRY THISCREATE TABLE #T (edu_id INT,STID_ID INT,QUAL_ID INT,PERCENTAGE INT)INSERT INTO #TSELECT 1 , 2 , 1 , 70 UNION ALLSELECT 2 , 2 , 2 , 70 UNION ALLSELECT 3 , 2 , 3 , 72 UNION ALLSELECT 4 , 3 , 1 , 90 UNION ALLSELECT 5 , 3 , 3 , 80 UNION ALLSELECT 6 , 3 , 2 , 60 SELECT STID_ID FROM (sELECT STID_ID,COUNT(STID_ID) AS A FROM #T WHERE PERCENTAGE>60 GROUP BY STID_ID) T WHERE A=3DROP TABLE #TIn Love... With Me! |
|
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-05-10 : 09:16:57
|
OR THIS;With cte as( Select STID_ID,COUNT(STID_ID) AS ACYEAR FROM #T WHERE PERCENTAGE>60 GROUP BY STID_ID)SELECT * FROM CTE WHERE ACYEAR=3In Love... With Me! |
|
|
|
|
|
|
|