如何优化几个“WHERE (Select ....) = value”来自同一张桌子

发布于 2024-11-06 14:30:30 字数 433 浏览 1 评论 0原文

对我来说很难起一个主题名称。但我可以举一个例子:

WHERE   (SELECT [ID_Line] FROM [Event] WHERE [Event].[Name]  = [A].[Col]) = 2
AND     (SELECT [DataType] FROM [Event] WHERE [Event].[Name]  = [A].[Col]) = 2

在这里,当我确实需要类似的东西时,我正在处理 2 个查询:

WHERE   (SELECT [ID_Line],[DataType] FROM [Event] WHERE [Event].[Name]  = [A].[Col]) = 2,2

但是 SQL 不适用于元组,所以我必须在这里进行 Inner Join 吗?

It's hard to compose a topic name for me. But I can show an example :

WHERE   (SELECT [ID_Line] FROM [Event] WHERE [Event].[Name]  = [A].[Col]) = 2
AND     (SELECT [DataType] FROM [Event] WHERE [Event].[Name]  = [A].[Col]) = 2

Here I'm processing 2 queries when I really need something like that :

WHERE   (SELECT [ID_Line],[DataType] FROM [Event] WHERE [Event].[Name]  = [A].[Col]) = 2,2

but SQL doesn't work with tuples, so must I make Inner Join here ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乖乖兔^ω^ 2024-11-13 14:30:30

您可以尝试这样的操作:

WHERE EXISTS (
    SELECT [ID_Line] FROM [Event] WHERE
        [Event].[Name]  = [A].[Col] AND
        [Event].[ID_Line] = 2 AND
        [Event].[DataType] = 2
)

如果您提供有关完整查询和数据库结构的更多信息,则可以给出更准确的答案。这可能不是最好的解决方案。

you can try something like this :

WHERE EXISTS (
    SELECT [ID_Line] FROM [Event] WHERE
        [Event].[Name]  = [A].[Col] AND
        [Event].[ID_Line] = 2 AND
        [Event].[DataType] = 2
)

If you provide more information about the complete query and your database structure, a more precise answer could be given. It is possible that this isn't the best solution.

高冷爸爸 2024-11-13 14:30:30

您可以尝试使用熔化操作符来熔化场。在 ORACLE PL/SQL 中,您使用 || (双管),例如。

You can try to melt the fields using a melting operator. In ORACLE PL/SQL you use || (double pipe), for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文