select A.code,A.name,avg(score) as 平均分
from A,B
where A.id=B.id
groud by A.code,A.name
你试试可以吗?
不知道你的表连接如何
第三题
select department ,b.score AS 最高分
from a a, b b
where a.id=b.id
group by department
第四题
update (select * from a a,b b where department='销售部' and b.score<80 and a.id=b.id ) c
set c.score=c.score+10;
select department, count(1) as total from tab_a group by department;
2.相关人员,平均成绩
select t1.code, t2.name, avg(t2.score) as avg_score
from tab_a t1
inner join tab_b t2 on t1.code = t2.code group by t1.code, t1.name
3.各部门最高分
select t1.department, max(t2.score) as max_score
from tab_a t1
inner join tab_b t2 on t1.code = t2.code group by t1.department
4.销售部,得分<80 +10
update tab_b set score = score +10
where code in (
select t2.code
from tab_a t1
inner join tab_b t2 on t1.code = t2.code
where t1.department='销售部' and t2.score < 80
)
1.select count(*) as '销售部门总人数 ' from A where department like '%销售部%';
2,3,4同上,不过department=‘销售部’最好改成 department like '%销售部%',这是因为往往在填数据库数据,会由于空格什么的符号影响到最终的结果,第二个只需根据code分组即可
我想知道你这两张表的id和code是什么关系,为什么两张表都有id和code?