How to calculate count?
-
Hi My Sql query is returing below resultset. SNO Id Count 1 101 2 102 3 104 4 102 5 106 6 102 7 104 I want if Id is repeating like 102 and 104 is repeating in above resulset .it should display count as: SNO Id Count 1 101 1 2 102 1 3 104 1 4 102 2 5 106 1 6 102 3 7 104 2 Please help how i write query for calculating clount value. Its urgent Plz help asap. Thanks
-
Hi My Sql query is returing below resultset. SNO Id Count 1 101 2 102 3 104 4 102 5 106 6 102 7 104 I want if Id is repeating like 102 and 104 is repeating in above resulset .it should display count as: SNO Id Count 1 101 1 2 102 1 3 104 1 4 102 2 5 106 1 6 102 3 7 104 2 Please help how i write query for calculating clount value. Its urgent Plz help asap. Thanks
Hi Try this:
SELECT SNO, Id, ( SELECT (COUNT(*) + 1) FROM table1 b WHERE b.SNO < a.SNO AND a.Id = b.Id) FROM table1 a
ORSELECT SNO, Id, ( SELECT COUNT(*) FROM table1 b WHERE b.SNO <= a.SNO AND a.Id = b.Id) FROM table1 a
Harini