SELECT
t1.DOC,
t1.TYPE,
COUNT(*) AS [Ino Seq]
FROM
MyData AS t1
INNER JOIN
MyData AS t2
ON t2.DOC = t1.DOC
AND t2.Ino <= t1.Ino
GROUP BY
t1.DOC,
t1.TYPE
ORDER BY 1, 3
select g.CODE
, count(*)-1 as C_NO
, g.NAME
from MyTable as g
left join MyTable as o
on g.CODE = o.CODE
and g.NAME >= o.NAME
group by g.CODE
, g.NAME;
SELECT A.*,
(SELECT COUNT(*) FROM tblNames WHERE A.ID>=ID) AS RowNum
FROM tblNames AS A
ORDER BY A.ID;