Skip to content Skip to sidebar Skip to footer

Sql Count With Inner Join For Single Table

I have a table like this: Name Id Amount Name1 1 99 Name1 1 30 Name1 9 120.2 Name2 21 348 Name2 21 21 Name3 41 99 I want to s

Solution 1:

SELECT
       [Name],
       [Id],
       count([Amount]) as 'Count'
FROM 
       table1
GROUP BY [Name], [Id]

Solution 2:

SELECT
A.[Name],
A.[Id]
FROM table1 A
INNER JOIN (
            SELECT
            table1.[Id],
            count([Amount]) as 'Count'
            FROM 
                table1
            GROUP BY table1.[Id]
       )
B ON A.[Id] = B.[Id]

Post a Comment for "Sql Count With Inner Join For Single Table"