34,590
社区成员
发帖
与我相关
我的任务
分享
select s_name,c_name from stu a left join class b
on a.s_cid = b.c_id
where count(a.c_name)> 20 and charindex('三',c_name)> 0
order by count(a.c_name) desc
with temptable as
(
select s_name ,c_name from stu,class where s_cid=c_id and c_name like '%三%' and c_id in
(
select c_id from stu,class where s_cid = c_id
group by c_id having(count(s_id)>=20)
)
)
select s_name ,c_name,
(select count(c_name) from temptable te where te.c_name = tt.c_name) as cal --计算出班级
from temptable tt order by cal desc
select a.s_name, c.c_name from stu a inner join
(select count(1) as s_num , s_cid from stu group by s_cid) b on a.s_cid=b.s_cid
inner join class c on a.s_cid=c.c_id
where b.s_num>20 and c.c_name like '%三%'
order by b.s_num desc
select s_sname,c_name from
(select stu.s_sname,class.c_name,stu.s_cid from stu,class where stu.s_cid=class.c_id) a,
(select s_cid,count(1) as sNo from stu group by s_cid having count(1)>20) b
where
a.s_cid=b.s_cid
order by b.sNo desc
select * from
(select s_sname,c_name from stu,class where s_cid=c_id) a,
(select s_cid,count(1) as sNo from stu group by s_cid having count(1)>20) b
where
a.s_cid=b.s_cid
order by b.sNo desc
---1、班级人数大于20。。
select count(distinct a.s_name)t,b.c_name from stu a,class b
where a.s_cid=b.c_id
group by b.c_name
having count(distinct a.s_name)>20
---2、班级名称有“三”的
select a.s_name,b.c_name from stu a,class b
where a.s_cid=b.c_id and b.c_name like'%三%'
-----3、按班级人数降序排列。
select count(distinct a.s_name)t,b.c_name from stu a,class b
where a.s_cid=b.c_id
group by b.c_name
order by t desc
select s_sname,c_name from stu,class where s_cid=c_id and s_cid in(
select s_cid from stu group by s_cid having count(*)>20 )and c_name like %三%