求助数据库达人有些地方不解

来源:百度知道 编辑:UC知道 时间:2024/06/06 00:21:32
update test set departName='B'
from test a join (
select departID
from test
group by departID
having count(*)>10) b
on a.departID =b.departID

能不能请大师们解释一下这个语法 虽然大致能看懂,但是join having等不太明白
大师们,这个b是哪里出来的
原题是这个使用存储过程查询出员工数大于10的部门ID和部门名称,并将部门名称改为B,中间要求使用事务回滚.
create table test
{
stuID int identity(1,1) not null,
stuName varchar(20) not null,
departID int identity(1,1) not null,
departName varchar(20) not null,
}

如果谁能完整的写出来,50分,谢谢

a b都是定义的表的别名啊。b 可以看成子查询 (select departID from test group by departID having count(*)>10)得出的结果临时保存在表b里;
group by 与HAVING一起使用,可以理解成按departID分组,找出新的分组下计数count(*)>10的departID;

事务回滚没接触过,不知道。

自定义的B吧
还有其他的没写吧
比如存储过程等上有没啊