一SQL句子的写法。。

ziyue 2002-04-07 03:57:15
表1与表2同结构。
表1 表2
ID DD SUM ID DD SUM
1 1 40 1 1 50
2 1 50 2 1 30
3 2 30 3 2 40
4 2 60 4 2 60
6 3 50 5 3 40
删除表1中,与表2中,
同ID,同DD,但 表1.SUM>=表2.SUM 的记录。。
结果为
表1
ID DD SUM
1 1 40
3 2 30
6 3 50

...全文
33 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
mmzxg 2002-04-07
  • 打赏
  • 举报
回复
更正:
delete from 表1 b1 (select * from b1 join 表2 b2 on b1.id=b2.id
and b1.dd=b2.dd where b1.sum1<b2.sum1)
hx 2002-04-07
  • 打赏
  • 举报
回复
DELETE * FROM A WHERE EXISTS (SELECT * FROM B WHERE A.ID=B.ID,A.DD=B.DD,A.SUM >=B.SUM)
thorkhan 2002-04-07
  • 打赏
  • 举报
回复
用Select語句就可以出結果﹐Delete就不可以﹐是不是表結构的問題﹐就是在實際應用中這樣的結构應該优化
dododo 2002-04-07
  • 打赏
  • 举报
回复
delete from 表1 where 表1.id in
(select 表1.id from 表1 b1 join 表2 b2 on b1.ID=b2.ID and b1.DD=b2.DD where b1.sum >= b2.sum)
joyu 2002-04-07
  • 打赏
  • 举报
回复
tangyong_delphi()和 blackhawk_yps(原来是这样) 的写法应该可以
blackhawk_yps 2002-04-07
  • 打赏
  • 举报
回复
delete table1 from table1,table2 where table1.ID=table2.ID and
table1.DD=table2.DD and table1.SUM>table2.SUM
wangsitao 2002-04-07
  • 打赏
  • 举报
回复
重新设计一下表结构
wangsitao 2002-04-07
  • 打赏
  • 举报
回复
delete * from 表1 as a where a.id in (select 表1.id from 表1,表2 where 表1.id= 表2 .id and 表1.dd= 表2 .dd and 表1.sum> 表2 .sum)
Hibert 2002-04-07
  • 打赏
  • 举报
回复
delete * from 表1,表2 where 表1.id=表2.id and 表1.dd=表2.dd and 表1.sum>=表2.sum
然后
select * from 表1
ziyue 2002-04-07
  • 打赏
  • 举报
回复
如果在表2里。。
出现 ID和DD,有重复的记录,(SUM不同)怎么办。。(这里,按最小的SUM来计算)
Hibert 2002-04-07
  • 打赏
  • 举报
回复
delete * from 表1,表2 where 表1.id=表2.id and 表1.dd=表2.dd and 表1.sum>=表2.sum
给分吧!!
SnHnBn 2002-04-07
  • 打赏
  • 举报
回复
重新设计一下表结构和算法吧?
tangyong_delphi 2002-04-07
  • 打赏
  • 举报
回复
delete from 表1 where 表1.id= 表2 .id and 表1.dd= 表2 .dd and 表1.sum> 表2 .sum
tangyong_delphi 2002-04-07
  • 打赏
  • 举报
回复
delete from 表1.id= 表2 .id and 表1.dd= 表2 .dd and 表1.sum> 表2 .sum

mmzxg 2002-04-07
  • 打赏
  • 举报
回复
delete 表1 from (select * from b1 join 表2 b2 on b1.id=b2.id and b1.dd=b2.dd where b1.sum<b2.sum)
Hibert 2002-04-07
  • 打赏
  • 举报
回复
delete * from 表1,表2 where 表1.id=表2.id and 表1.dd=表2.dd and 表1.sum>=表2.sum
ziyue 2002-04-07
  • 打赏
  • 举报
回复
不是SELECT 是DELETE。我想删除表里的记录。
kaden 2002-04-07
  • 打赏
  • 举报
回复
select * from 表1 b1 join 表2 b2 on b1.ID=b2.ID and b1.DD=b2.DD where b1.sum < b2.sum

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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