Groups | Blog | Home
all groups > sql server (alternate) > october 2004 >

sql server (alternate) : query help


parth_ai NO[at]SPAM yahoo.com
10/27/2004 10:34:55 AM
I have the following table -

Name Enrolment# File#
x 422 011
y 421 022
z 444 023
a 345 024


I have to produce the following table -

S.No Name Enrolment# File#
1 a 345 024
2 y 421 022
3 x 422 021
4 z 444 023


Could someone please help me out with the SQL query to do the
operation above? I know how to sort by enrolment# but how do I produce
the first column of the target table?

Thanks in Advance.

Hugo Kornelis
10/27/2004 11:22:48 PM
[quoted text, click to view]

Hi Parth,

Try the following queries. Since you didn't provide CREATE TABLE and
INSERT statements to base my tests on, I didn't test them.

SELECT COUNT(*) AS "S.No",
a.Name, a.Enrolment#, a.File#
FROM YourTable AS a
INNER JOIN YourTable AS b
ON b.File# >= a.File#
GROUP BY a.Name, a.Enrolment, a.File#
ORDER BY a.File# DESC

SELECT (SELECT COUNT(*)
FROM YourTable AS b
WHERE b.File# >= a.File#) AS "S.No",
a.Name, a.Enrolment#, a.File#
FROM YourTable AS a
ORDER BY a.File# DESC


Best, Hugo
--

parth_ai NO[at]SPAM yahoo.com
10/28/2004 10:27:10 AM
Thanks Hugo.



[quoted text, click to view]
AddThis Social Bookmark Button