Connecting Tech Pros Worldwide Forums | Help | Site Map

filter data - SQL

Newbie
 
Join Date: Oct 2007
Posts: 6
#1: Oct 21 '07
Table :

Name Month Marks

A Sept 150
B Sept 200
C Sept 100
D Sept 500

A Oct 100
B Oct 225
C Oct 300
D Oct 115



Query
-----
Select only those students where students score more marks than previous month.
like improving students




REsults should be
-------
B OCT 225
C Oct 300

Jim Doherty's Avatar
Moderator
 
Join Date: Aug 2007
Location: Derbyshire,England
Posts: 639
#2: Oct 21 '07

re: filter data - SQL


Quote:

Originally Posted by jkshetty

Table :

Name Month Marks

A Sept 150
B Sept 200
C Sept 100
D Sept 500

A Oct 100
B Oct 225
C Oct 300
D Oct 115



Query
-----
Select only those students where students score more marks than previous month.
like improving students




REsults should be
-------
B OCT 225
C Oct 300


What have you tried in place yourself to answer this?
The SQL (see below) to display the result as you have there will be flawed in a real sense. Can you see why?

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT     TOP 100 PERCENT A.Name, A.[Month], A.Marks
  3. FROM         dbo.tblMarks A INNER JOIN
  4.                      dbo.tblMarks B ON A.Name = B.Name AND A.Marks > B.Marks AND B.[Month] > A.[Month]
  5.  
Jim :)
Reply


Similar Microsoft SQL Server bytes