Establishing a Count of Unique Records utilizing Parameters

D

DEL

I'm trying to create a table which counts off groupings of unique values.
Example:

Subj Course# SeqNo.
MAT 101 1
MAT 101 1.5
MAT 101 2
BIO 101 1.5
BIO 101 1.75
BIO 101 1.8
BIO 101 1.9


My desired table is simply to increment of each entry for the unique Subj &
Course# by 1

End Result Desired:

Subj Course# SeqNo. Countoff
MAT 101 1 1
MAT 101 1.5 2
MAT 101 2 3
BIO 101 1.5 1
BIO 101 1.75 2
BIO 101 1.8 3
BIO 101 1.9 4

Any help would be appreciated!

R/S,

DEL
 
K

KARL DEWEY

Try this --
SELECT Subj, [Course#], [SeqNo.], (SELECT COUNT(*)
FROM [YourTable] T1
WHERE T1.Subj = T.Subj
AND T1.Course# <= T.Course#) AS Countoff
FROM [YourTable] AS T
ORDER BY Subj, [Course#];
 
K

KARL DEWEY

Read it again - try this instead --
SELECT Subj, [Course#], [SeqNo.], (SELECT COUNT(*)
FROM [YourTable] T1
WHERE T1.Subj = T.Subj
AND T1.[Course#] = T.[Course#]
AND T1.[SeqNo.] <= T.[SeqNo.] ) AS Countoff
FROM [YourTable] AS T
ORDER BY Subj, [Course#];
 
D

DEL

Very helpful ... thanks!

R/S,

DEL

KARL DEWEY said:
Read it again - try this instead --
SELECT Subj, [Course#], [SeqNo.], (SELECT COUNT(*)
FROM [YourTable] T1
WHERE T1.Subj = T.Subj
AND T1.[Course#] = T.[Course#]
AND T1.[SeqNo.] <= T.[SeqNo.] ) AS Countoff
FROM [YourTable] AS T
ORDER BY Subj, [Course#];

DEL said:
I'm trying to create a table which counts off groupings of unique values.
Example:

Subj Course# SeqNo.
MAT 101 1
MAT 101 1.5
MAT 101 2
BIO 101 1.5
BIO 101 1.75
BIO 101 1.8
BIO 101 1.9


My desired table is simply to increment of each entry for the unique Subj &
Course# by 1

End Result Desired:

Subj Course# SeqNo. Countoff
MAT 101 1 1
MAT 101 1.5 2
MAT 101 2 3
BIO 101 1.5 1
BIO 101 1.75 2
BIO 101 1.8 3
BIO 101 1.9 4

Any help would be appreciated!

R/S,

DEL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top