MySQL 中计算差集可以使用 'NOT IN' 或 'LEFT JOIN' 语句。

  1. 使用 'NOT IN' 语句:
SELECT * FROM table1 WHERE column1 NOT IN (SELECT column2 FROM table2);

这将从 table1 中选择 column1 不在 table2 中 column2 的所有行。

  1. 使用 'LEFT JOIN' 语句:
SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.column1 = table2.column2 WHERE table2.column2 IS NULL;

这将从 table1 中选择不与 table2 中的任何行匹配的所有行。

MySQL 差集计算:NOT IN 与 LEFT JOIN 方法

原文地址: https://www.cveoy.top/t/topic/odCW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录