I need to create an instance index for a table group by studentid and classid
CREATE TABLE Table1
(ClassID varchar(10),
StudentID varchar(10),
Fee1 money,
fee2 money,
fee3 money
)
INSERT INTO Table1
VALUES ('02003', '00001', 20,10,15)
INSERT INTO Table1
VALUES ('02003', '00001', 25,15,15)
INSERT INTO Table1
VALUES ('02005', '00001', 10,10,15)
INSERT INTO Table1
VALUES ('02005', '00004', 20,10,15)
INSERT INTO Table1
VALUES ('02005', '00004', 20,10,15)
INSERT INTO Table1
VALUES ('02005', '00004', 20,10,15)
SELECT * FROM Table1
the output i'd like to see is :
ClassIDStudentIDFee1Fee2Fee3Index
020030000120.0010.0015.001
020030000125.0015.0015.002
020050000110.0010.0015.001
020050000420.0010.0015.001
020050000420.0010.0015.002
020050000420.0010.0015.003
Any suggestions on what method to use? Thanks.
Here it is,
Code Snippet
SELECT
ClassID,StudentID,Fee1, Fee2, Fee3,
ROW_NUMBER() over (Partition By ClassId, StudentId Order By ClassId, StudentId) as Index
FROM
Table1
|||
Use ROW_NUMBER()...something like this (didn't test it)
select
ClassID
,StudentID
,Fee1
,Fee2
,Fee3
,RANK() OVER (PARTITION BY ClassID, StudentID ORDER BY Fee1) AS 'Index'
from
|||Table1
Thanks!!
No comments:
Post a Comment