我的查询是
Select
NO,
Timestamp,
Event_type,
Comments
From TableA
Where NO = '12345';
但对于Event_type
,我只想选择何时event_type in ('ABC_XYZ','Comment_Change'
)
并且Comments
字段必须与Cause:%
(event_type = 'Comment_change'
)
我怎样才能实现这个条件?
答案 0 :(得分:1)
Select
NO,
Timestamp,
Event_type,
Comments
From TableA
Where NO = '12345'
and event_type = 'Comment_Change'
And Comments like 'Cause:%';
这似乎是你要求的。
答案 1 :(得分:1)
在mysql中:
Select
no,
Timestamp,
if(event_type='comment_change',event_type,null) as event_type,
Concat('Cause: ', comments) as comments
from TableA
where no='12345';
答案 2 :(得分:1)
带有案例构造
select case when comments like 'Cause:%'
and event_type in ('ABC_XYZ','Comment_Change') then event_type
else 'something else' event_type
from tableA
where no = '12345'
答案 3 :(得分:1)
尝试:
Select
NO,
Timestamp,
Event_type,
Comments
From TableA
Where event_type = 'ABC_XYZ' or
(event_type = 'Comment_Change' and Commentsfield like 'Cause:%')