0

我的查询是

Select 
       NO,
       Timestamp,
       Event_type,
       Comments
From   TableA
Where NO = '12345';

但是对于Event_type,我只想选择 when event_type in ('ABC_XYZ','Comment_Change')

并且Comments字段必须像Cause:%(when event_type = 'Comment_change')

我怎样才能达到这个条件?

4

4 回答 4

1
Select 
       NO,
       Timestamp,
       Event_type,
       Comments
From   TableA
Where NO = '12345'
and event_type = 'Comment_Change' 
And Comments like 'Cause:%';

这似乎是你所要求的。

于 2013-06-05T16:18:46.120 回答
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';
于 2013-06-05T16:20:54.923 回答
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'
于 2013-06-05T16:21:39.397 回答
1

尝试:

Select 
       NO,
       Timestamp,
       Event_type,
       Comments
From   TableA
Where event_type = 'ABC_XYZ' or
      (event_type =  'Comment_Change' and Commentsfield like 'Cause:%')
于 2013-06-05T16:23:21.720 回答