0

有人可以帮我处理一个有表的sql查询吗

Col A | Col B
-------------
A       B
C       D
E       F
B       A

如何删除 {B, A} 或选择 {B, A}

问题是:

If two students A and B are friends, and A likes B but not vice-versa,
remove the Likes tuple.

我已经弄清楚了 A 和 B 是朋友并且 A 喜欢 B 的表,但我不知道如何删除 B 喜欢 A 元组

我有

select friend.id1, friend.id2
from friend, likes
where friend.id1 = likes.id1 and friend.id2 = likes.id2
4

2 回答 2

1

我以前看过这个家庭作业...

DELETE FROM Likes
WHERE ID1 IN (SELECT L.ID1
                       FROM Friend F,Likes L
                       WHERE F.ID1 = L.ID1 AND F.ID2 = L.ID2
                       AND F.ID1 NOT IN (SELECT ID2 
                                         FROM Likes
                                         WHERE ID1=L.ID2 AND ID2=L.ID1))

尝试自己解决这些问题 - 如果无法解决,请尝试在 Google 上搜索。

于 2013-02-03T06:16:20.197 回答
0
DELETE FROM friends f1
WHERE NOT EXISTS (
    SELECT *
    FROM friends f2
    WHERE f2.a = f1.b AND f2.b = f1.a
    );

注意:这可能在 mysql 中不起作用,因为它不允许在子查询中引用目标表。

于 2014-08-12T00:21:48.830 回答