Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Ottenere il conteggio dalle tabelle sql

Prova questo:

BEGIN


SELECT     tbl_SubCategory.Name AS SubCategoryName, COUNT(*) AS TotalCompanies
FROM       tbl_Category INNER JOIN
                      tbl_Company_Category_Map ON tbl_Category.Id = tbl_Company_Category_Map.CategoryId INNER JOIN
                      tbl_SubCategory ON tbl_Company_Category_Map.SubCategoryId = tbl_SubCategory.Id
WHERE     (tbl_Company_Category_Map.CategoryId = @Id)
Group By tbl_SubCategory.Name
ORDER BY tbl_SubCategory.Name

END