22,209
社区成员
发帖
与我相关
我的任务
分享
create TABLE Table1
(
ID int identity(1,1) primary key NOT NULL,
classid int,
sex varchar(10),
age int,
)
Insert into Table1 values(1,'男',20)
Insert into Table1 values(2,'女',22)
Insert into Table1 values(3,'男',23)
Insert into Table1 values(4,'男',22)
Insert into Table1 values(1,'男',24)
Insert into Table1 values(2,'女',19)
Insert into Table1 values(4,'男',26)
Insert into Table1 values(1,'男',24)
Insert into Table1 values(1,'男',20)
Insert into Table1 values(2,'女',22)
Insert into Table1 values(3,'男',23)
Insert into Table1 values(4,'男',22)
Insert into Table1 values(1,'男',24)
Insert into Table1 values(2,'女',19)
select classid 班级,COUNT(*) '>20岁人数' from Table1 where sex='男' group by classid,age having age>'20'