作者:happy雨之泪 | 来源:互联网 | 2023-05-17 14:16
I have these 2 tables:
我有这两个表:
Table SW_ITEM
:
表SW_ITEM:
ID SWID ITEM_ID
1 1 99
2 2 99
3 5 99
4 2 100
5 1 100
6 1 101
7 2 102
Table ITEM
:
表项目:
ID FILENAME
99 abc
100 def
101 geh
102 ijk
column ITEM_ID
is a foreign key to the column ID
of table ITEM
.
列ITEM_ID是表ITEM的列ID的外键。
So I want all filenames which have the SWID "1" AND "2" (that would be ITEMID 99 and 100, so their filenames are "abc" and "def")
所以我想要所有SWID为“1”和“2”的文件名(即ITEMID 99和100,所以他们的文件名是“abc”和“def”)
Here I have to say that it is possible that ITEM_ID
has more than one entry with the same SWID, so I cannot use this SQL:
在这里我不得不说ITEM_ID有可能有多个具有相同SWID的条目,所以我不能使用这个SQL:
SELECT ITEM_ID FROM SW_ITEM
WHERE SWID IN (1,2)
GROUP BY ITEM_ID
HAVING COUNT(ITEM_ID) = 2
So is there any other possibility to get all entries which have the SWID 1 and 2 (creating a join for every SWID is also not an option - because with many entries it would be really slow)
那么还有其他任何可能获得具有SWID 1和2的条目(为每个SWID创建连接也不是一个选项 - 因为有很多条目它会非常慢)
Kind regards
亲切的问候
2 个解决方案