簡體   English   中英

從table1刪除,其中column1大於table2.column1乘以2

[英]DELETE from table1 where column1 is greater than table2.column1 multipled by 2

如您所見,標題非常好。

嘗試刪除其中一個列的值是另一張表的兩倍的行。

select DB
delete 
from table1
where table1.id IN (select table2.id where table1.price > table2.price*2)

我想查詢相匹配的id column ,並刪除所有table1是有一個行table1.column1兩倍大的對口table2.column1 我應該使用什么語法?

您需要在子查詢中聯接表。 下面的示例假設兩個表都有一個唯一的名為“ id”的id列

delete 
from table1
where table1.id IN (
select table2.id from table1, table2 where 
table1.id = table2.id
and
table1.price > (table2.price*2))

從刪除table1匹配id和條件pricetable1比更大的table2

DELETE FROM table1
FROM   table1 INNER JOIN ON
table1 .id = table2.id
WHERE  (table1 .price  > table2.price* 2)

如果兩個表可以通過其id連接,則只需執行以下操作:

select DB
delete 
from table1
where table1.id IN (
  select table2.id from table1 inner join table2 on table2.id=table1.id
  where table1.price > table2.price*2)
delete from table1 where id in 
(select id from table1 join table2 on table1.id = table2.id
where table1.column1 > 2*table2.column1)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM