如何撰写CASE声明?

时间:2015-09-18 19:47:55

标签: mysql sql case

我正在尝试编写一个简单的case语句,它在一个值的情况下连接两个字段,但默认为与另一个元素连接的原始字段。

SELECT 
RCDEA.data_element_ID,
RCDEA.answer_ID,
RCDEA.answer_text,
AA.name answer_name,
(
 CASE 
    WHEN MM.export_value = 'MAYBACH' THEN CONCAT('S', "|", RCDEA.create_DTM) 
    WHEN MM.export_value = 'PICPE' THEN CONCAT('PACPE', "|", RCDEA.create_DTM) 
    WHEN MM.export_value = 'POCPE' THEN CONCAT('PACPE', "|", RCDEA.create_DTM) 
    ELSE CONCAT(MM.export_value, "|", RCDEA.create_DTM) 
) AS poi_multi,

MM.export_value_2 AS mapping_export_value_2,
RCDEA.create_DTM,
CAST(DATE_FORMAT(RCDEA.create_DTM,"%m%d%Y") AS CHAR) AS source_date,
CAST(DATE_FORMAT(RCDEA.create_DTM,"%H%i%s") AS CHAR) AS source_time,
CASE 
    WHEN RCDEA.data_element_ID = 11177 THEN CAST(DATE_FORMAT(DATE_ADD(F.create_DTM, INTERVAL 180 DAY), "%m%d%Y") AS CHAR) ELSE '' END AS cert_expn_date_source,
F.event_token_ID
FROM efn.R_Consumer_Data_Element_Answer RCDEA
JOIN efn.Footprints F ON RCDEA.footprint_ID = F.footprint_ID
    AND F.consumer_ID = RCDEA.consumer_ID
LEFT JOIN efn.Answers AA ON RCDEA.answer_ID = AA.answer_ID
LEFT JOIN kettle_data_transfer.Mappings MM ON RCDEA.data_element_ID = MM.data_element_ID AND RCDEA.answer_ID = MM.answer_ID
AND MM.data_transfer_ID = 12

1 个答案:

答案 0 :(得分:0)

从第一个Array语句中删除大括号()并添加CASE

END AS