首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

二个查询 难度

2011-12-11 
2个查询 难度一a表id1,id2,sid1,id22个是主键b表id1,id2,s1id1,id22个是主键要求写一个SQL语句删除a表中id

2个查询 难度

a表
id1,id2,s
id1,id2     2个是主键

b表
id1,id2,s1
id1,id2     2个是主键

要求写一个SQL语句删除a表中id1,id2和b表中id1,id2相同的记录!


a表
id1,s1


b表
id1,s2

要求对a表id1字段=b表id1时候,将a表s1设置为b表根据id1分组sum(s2)值,
即select   id1,sum(s2)   from   b   group   by   id1




[解决办法]
up

[解决办法]
delete from a
where exists (select 'Z ' from b where a.id1=b.id1 and a.id2=b.id2)

update a
set s1=(select sum(s2) from b where a.id1=b.id1 group by b.id1)
[解决办法]
delete a
from a
where exists(select 1 from b where b.id1 = a.id1 and b.id2 = a.id2


update c
set s1 = temp.curSum
from c, (select id1, sum(s2) as curSum from d group by id1)temp
where c.id1 = temp.id1

热点排行
Bad Request.