简体   繁体   English

SQL 连接同一个表

[英]SQL joining with the same table

I have a table with EVENT_ID column its have multiple entries against this event_id and then have event_name column.我有一个带有 EVENT_ID 列的表,它有多个针对这个 event_id 的条目,然后有 event_name 列。 so my requirement is I need to select couple event-name along with the finalized event records if the one of the event_name is finalized_Event and in the passed event_ids, otherwise ignore that event_id, is there any way I can combine all query in one SQL.所以我的要求是,如果 event_name 是 finalized_Event 并且在传递的 event_ids 中,我需要选择一对 event-name 和最终事件记录,否则忽略该 event_id,有什么方法可以将所有查询组合到一个 SQL 中。

       Select * from EVENT where EVENT_ID in ('0cbe3a81-8102-4eee-b8ef-07485f58cf0a','42b47725-4cc3-4620-9051-652d5409e69a','6e1b73d1-2f20-410c-80d2-89b0ccfde473')
   and 
    ( select * from EVENT where EVENT_NAME = 'FinalisedEvent' and (EVENT_NAME = 'CreatedEvent' or EVENT_NAME = 'DeletdEvent'))

Do you want something like:你想要这样的东西:

SELECT e1.* 
FROM EVENT e1
INNER JOIN EVENT e2
  ON e1.EVENT_ID = e2.EVENT_ID
  AND (e2.EVENT_NAME = 'CreatedEvent' OR e2.EVENT_NAME = 'DeletdEvent')
WHERE e1.EVENT_ID in ('0cbe3a81-8102-4eee-b8ef-07485f58cf0a','42b47725-4cc3-4620-9051-652d5409e69a','6e1b73d1-2f20-410c-80d2-89b0ccfde473')
AND e1.EVENT_NAME = 'FinalisedEvent'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM