两个表更新数据sql语句

zhouboat 2008-11-24 03:03:15
A表(岗位,试卷,通过数量) //一个岗位对应多个试卷;
B表(试卷,成绩)

想得到:在A表里的通过数量=该岗位对应的试卷(成绩>60)的数量.

下面的语句不对,正确的应该如何写呢?
update A set 通过数量=(select count(distinct 试卷) from A,B where A.试卷=B.试卷 where B.成绩>60)

谢谢!



...全文
129 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
tang_fu 2008-11-25
  • 打赏
  • 举报
回复
update A set 通过数量=(select count(distinct 试卷) from A,B where A.试卷=B.试卷

where B.成绩>60
and A.岗位=‘something’ and A.试卷='something')
  • 打赏
  • 举报
回复
楼上正解啊.我JF谢谢
wangcan05528845048 2008-11-25
  • 打赏
  • 举报
回复
update a set a.通过数量=bb.数量 from (select 试卷,count(试卷) as 数量 from b where 成绩>60 group by 试卷) bb where a.试卷=bb.试卷
mjjzg 2008-11-24
  • 打赏
  • 举报
回复
没意义了,这还有什么好说的
tang_fu 2008-11-24
  • 打赏
  • 举报
回复
update A set 通过数量=(select count(distinct 试卷) from A inner join B on A.试卷=B.试卷 where B.成绩>60)
wangcan05528845048 2008-11-24
  • 打赏
  • 举报
回复


update A set 通过数量= bb.数量 from (select 试卷, Count(distinct 试卷 ) as 数量 from b where B.成绩>60) bb inner join A AA where AA.试卷=bb.试卷
hanyu021 2008-11-24
  • 打赏
  • 举报
回复
我有这个问题啊,呵呵
bbbbbb888888 2008-11-24
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 yashaov 的回复:]
引用 3 楼 Zhanlixin 的回复:
update A set 通过数量=bb.通过数量 from a,(select 试卷,count(*) 通过数量 from B group by 试卷 where 成绩>60) bb where A.试卷=bb.试卷


正解。
[/Quote]
正解.
llsen 2008-11-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 chinawes 的回复:]
update A set 通过数量=(select count(distinct 试卷) from A inner join B on A.试卷=B.试卷 where B.成绩>60)
[/Quote]

正解
yashaov 2008-11-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 Zhanlixin 的回复:]
update A set 通过数量=bb.通过数量 from a,(select 试卷,count(*) 通过数量 from B group by 试卷 where 成绩>60) bb where A.试卷=bb.试卷
[/Quote]

正解。
wangping_li 2008-11-24
  • 打赏
  • 举报
回复
[Quote=引用楼主 zhouboat 的帖子:]
A表(岗位,试卷,通过数量) //一个岗位对应多个试卷;
B表(试卷,成绩)

想得到:在A表里的通过数量=该岗位对应的试卷(成绩>60)的数量.

下面的语句不对,正确的应该如何写呢?
update A set 通过数量=(select count(distinct 试卷) from A,B where A.试卷=B.试卷 where B.成绩>60)

谢谢!
[/Quote]
UPDATE A SET 通过数量=(select count(B.*) FROM A,B WHERE A.试卷=B.试卷 AND B.成绩>60)
zhouboat 2008-11-24
  • 打赏
  • 举报
回复
需要的是一次更新全部的数据,而不是A.岗位=‘something’
谢谢各位.
yfcomeon 2008-11-24
  • 打赏
  • 举报
回复
update A set 通过数量=(select count(B.*) from A,B where A.试卷=B.试卷
and B.成绩>60
and A.岗位=‘something’
)
cooolchen 2008-11-24
  • 打赏
  • 举报
回复

update A set 通过数量=(select count(distinct 试卷) from A,B where A.试卷=B.试卷

where B.成绩>60
and A.岗位=‘something’ and A.试卷='something')
Zhanlixin 2008-11-24
  • 打赏
  • 举报
回复
update A set 通过数量=bb.通过数量 from a,(select 试卷,count(*) 通过数量 from B group by 试卷 where 成绩>60) bb where A.试卷=bb.试卷
chinawes 2008-11-24
  • 打赏
  • 举报
回复
update A set 通过数量=(select count(distinct 试卷) from A inner join B on A.试卷=B.试卷 where B.成绩>60)
cooolchen 2008-11-24
  • 打赏
  • 举报
回复
update A set 通过数量=(select count(distinct 试卷) from A,B where A.试卷=B.试卷

where B.成绩>60
and A.岗位=‘something’
)

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧