Question : SQL Returning record position / count together

Hi,

I want to return a record position and count as a varchar.  I can calculate the position by counting the records less that the current record, and the count by simply counting the records, but how i can i do this in 1 query and have them in seperate fields:

eg:      Pos      Count
      2      10

THere is also another criteria that needs to be applied im not sure if it will complicate issues. EG count will be SELECT COUNT(id) FROM tablename WHERE type=1;

Thanks,
Michael

Answer : SQL Returning record position / count together

do you mean

select id,count(*)
from table
where type = 1
group by id
order by id

?

or
select pos,num as [count]
from (
Select a.id, Num,count(*) as pos
from Table as A
Inner Join (
select id,count(*) as Num
from table
where type = 1
group by id
) as b
on A.id <=b.id
group by a.id,num
) as c
order by pos

?
 
Random Solutions  
 
programming4us programming4us