I have got this kind of table
| SessionId | Action |
----------------------
| 1 | LOGIN |
| 1 | INDEX |
| 3 | LOGIN |
| 1 | SHOW |
| 3 | DELETE |
| 1 | INSERT |
| 6 | LOGIN |
| 3 | LOGOUT |
| 5 | LOGIN |
I need to fetch count of all actions without LOGIN for each SessionId which has got LOGIN action.
| SessionId | count |
---------------------
| 1 | 3 |
| 3 | 2 |
| 5 | 0 |
| 6 | 0 |
And I am using sql server now (Mysql syntax will be ok)
EDIT: Added LEFT JOIN so that SessionId values 5 and 6 are included in the results. This also has the benefit of eliminating the subquery.