你怎么能写这个查询?
我有两张桌子。 表的结构如下。
TRAILERS_INVENTORY
- TRAILER_TYPE VARCHAR2(100)
- TRAILER_LENGTH INT
- TRAILER_WIDTH INT
- YEAR_OF_MANUFACTURE INT
NEW_INVENTORY
- NEW_INVENTORY_TYPE_ID INT、
- TRAILER_TYPE VARCHAR2(100)、
- TRAILER_LENGTH INT、
- TRAILER_WIDTH INT、
- UFACTURE INT
我想列出所有没有 NEW_INVENTORY_TYPE_ID 的预告片。我使用的是Oracle 9.2。
一种方法是使用集合运算,类似于
SELECT TRAILER_TYPE
FROM TRAILERS_INVENTORY
WHERE TRAILER_TYPE NOT IN (SELECT TRAILER_TYPE,
TRAILER_LENGTH,
TRAILER_WIDTH,
YEAR_OF_MANUFACTURE
FROM TRAILERS_INVENTORY
INTERSECT
SELECT TRAILER_TYPE,
TRAILER_LENGTH,
TRAILER_WIDTH,
YEAR_OF_MANUFACTURE
FROM NEW_INVENTORY);
还有其他可用的方法吗?
I have two tables.
The structure of tables is as follows.
TRAILERS_INVENTORY
- TRAILER_TYPE VARCHAR2(100)
- TRAILER_LENGTH INT
- TRAILER_WIDTH INT
- YEAR_OF_MANUFACTURE INT
NEW_INVENTORY
- NEW_INVENTORY_TYPE_ID INT,
- TRAILER_TYPE VARCHAR2(100),
- TRAILER_LENGTH INT,
- TRAILER_WIDTH INT,
- YEAR_OF_MANUFACTURE INT
I want to list all of the trailers that do not have a NEW_INVENTORY_TYPE_ID. I am using Oracle 9.2.
One approach is to use a set operation along the lines of
SELECT TRAILER_TYPE
FROM TRAILERS_INVENTORY
WHERE TRAILER_TYPE NOT IN (SELECT TRAILER_TYPE,
TRAILER_LENGTH,
TRAILER_WIDTH,
YEAR_OF_MANUFACTURE
FROM TRAILERS_INVENTORY
INTERSECT
SELECT TRAILER_TYPE,
TRAILER_LENGTH,
TRAILER_WIDTH,
YEAR_OF_MANUFACTURE
FROM NEW_INVENTORY);
IS THERE ANOTHER APPROACH AVAILABLE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我看到几个选项
或者:
I see a couple of options
Or:
那么,问题是如何在不使用“set”操作的情况下执行此查询?
请问为啥不用套装呢?
您在 SQL 中所做的一切都基于集合,但如果您想要一个更慢、不太优雅的解决方案,您可以将集合大小减少到 1 并使用 PL/SQL 循环遍历
TRAILERS_INVENTORY
。哎呀!这就是为什么集合操作是最佳选择。
:)
So, the question is how can you perform this query without using a "set" operation?
Can I ask why you wouldn't use a set?
Everything you do in SQL is based on sets, but if you want a slower, less elegant solution you can reduce your set size to 1 and loop through
TRAILERS_INVENTORY
using PL/SQL.Eek! That's why set operations are the way to go.
:)
怎么样:
What about: