Select count from another table to each row in result rows

前端 未结 5 700
北恋
北恋 2021-02-08 23:15

Here are the tables:

CREATE TABLE [dbo].[Classes](
    [ClassId] [int] NOT NULL,
    [ClassName] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_Classes] PRIMARY KEY CL         


        
5条回答
  •  清酒与你
    2021-02-08 23:50

     select c.ClassId,C.ClassName,COUNT(*) [Number of students]
     from Classes C,Students S
     where c.ClassId=S.ClassId
     group by C.ClassId,C.ClassName
    

提交回复
热议问题