我有餐桌食品,有以下限制
Food
Name(which has the dish name)
category (cuisine name)
DeskNo(The table that it is placed on)
Food:
Name Category Deskno
pasta Mexican 1
noodles Chines 1
friedrice Chinese 2
Tamarindrice Indian 2
我有一张带有
的通过表格ThroughAway
category1
category2
ThrowAway
Category1 Category2
Indian Chinese
Mexican Indian
如果category1和category2聚集在同一桌面上,那些菜肴将被扔掉。 我需要输出同一DeskNo中菜肴的名称,并且存在两者都可能落入ThrownAway的危险。需要一些帮助
答案 0 :(得分:2)
尝试此查询
SELECT Distinct a.Name AS Dish1, b.Name As Dish2
FROM Food a, Food b, ThroughAway c
WHERE a.Name <> b.Name AND a.Deskno = b.deskno AND
(a.category = c.category1 AND c.category2 = b.category) ;
自我加入,将同桌的菜肴与扔掉的桌子进行比较
答案 1 :(得分:0)
select f1.name, f2.name from ThrowAway t
inner join Food f1 on f1.Category = t.Category1
inner join Food f2 on f2.Category = t.Category2
where f1.deskno = f2.deskno
但你不应该像这样加入varchar或者smth,这是一个非常糟糕的做法。 添加ID,索引并加入它们。
答案 2 :(得分:0)
SELECT FOOD.DESKNO
FROM FOOD INNER JOIN
THROW ON FOOD.CATEGORY = THROW.CAT1 INNER JOIN
THROW AS THROW_1 ON FOOD.CATEGORY = THROW_1.CAT2
答案 3 :(得分:0)
食品
姓名(有菜名) 类别(美食名称) DeskNo(放置它的表)
食物: 名称分类Deskno 面食墨西哥1 面条中国1 Friedrice中文2 Tamarindrice Indian 2