select event_id,
IF(event_type!='C',e.event_title ,'') event_title,
IF(event_type='C', e.event_title ,'') event_subtitle
from event e where log_id='%s'
select event_id,
case when event_type<>'C' then e.event_title end as event_title,
case when event_type='C'then e.event_title end as event_subtitle
from event where log_id='%s';
例如:
SELECT ename ,
case when job='SALESMAN' then ename end as salesman_ename,
case when job<>'SALESMAN' then ename end as not_salesman_ename
FROM scott.emp;
SMITH SMITH
ALLEN ALLEN
WARD WARD
JONES JONES
MARTIN MARTIN
BLAKE BLAKE
CLARK CLARK
SCOTT SCOTT
KING KING
TURNER TURNER
ADAMS ADAMS
JAMES JAMES
FORD FORD
MILLER MILLER
H H
select event_id,
max(case when event_type <> 'C' then e.event_title end) as event_title,
max(case when event_type = 'C' then e.event_title end) as event_subtitle
from event e
where log_id = '%s'
group by event_id;
4条答案
按热度按时间hi3rlvi21#
例如,代码“起作用”
如果您的数据模型不是这样的,或者基于我的示例数据的输出不是您所期望的,请将示例数据和所需的输出作为文本添加到问题中。
blmhpbnm2#
检查此项:
例如:
lzfw57am3#
我想知道你是否需要:
6ovsh4lw4#
你在写什么
event_title
在这两种情况下,但根据你的要求,我知道你想要IF(event_type='C', e.event_subtitle ,'') event_subtitle
更改自到