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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL-query

Author  Topic 

chinlax
Starting Member

30 Posts

Posted - 2011-09-29 : 00:01:30
Hi all,
I am quite new to SQL SERVER 2008, i am learning all the basic queries,
can any one help me out in solving the below problem.


select top 1 student from each Class in a table. Table Columns are ClassName | StudentName | AggregateofMarks


Thanks,

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-29 : 00:06:19
can we see what you tried till now?
I can give you hint

Read about ROW_NUMBER() function and PARTITION BY in books online.
Try it out and post if you face any issues so that we can help you out

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

chinlax
Starting Member

30 Posts

Posted - 2011-09-29 : 05:47:15
Hi,
Ok let explain , how much i have worked with, the question is
select top 1 student from each Class in a table. Table Columns are ClassName | StudentName | AggregateofMarks
So what did i do is, i created two tables named Class and Marks
Class Table has two columns->class name, student name
Marks Table has two columns->Class name, Aggregate Marks

so how do i get the topper in each class, and my question is how do get highest marks, from each class having only aggregate marks of each class.

Can any one help me out..............

Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-29 : 07:58:55
nope. the table design itelf is wrong. why marks table is having classname? ho can you relate marks to a class? it should be related to student instead. the best way to design it will be having seperate table for student,class and marks. marks will have details of student (studentid) and course/class

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -