如何在mysql中查询时从select case中获取值

时间:2016-11-17 10:56:46

标签: mysql

select     `event_attendees_mapping`.`attendees_status_id`
            FROM
                `event_attendees_mapping`
            WHERE
                ((`event_attendees_mapping`.`event_schedule_id` = 1)
                    AND (`event_attendees_mapping`.`employee_code` = 'TJU_741')                    
                    ) 

使用此查询,我能够获得我在案件和条件时转换的价值。

 select case     
           when (select     `event_attendees_mapping`.`attendees_status_id`
            FROM
                `event_attendees_mapping`
            WHERE
                ((`event_attendees_mapping`.`event_schedule_id` = 1)
                    AND (`event_attendees_mapping`.`employee_code` = 'TJU_741')                    
                    )  )then    1

                    else
                    0
                    end

但是我在字段列表中收到错误未知表'event_attendees_mapping'而从查询中我能够获得价值请告诉我哪里出错了请建议我。

1 个答案:

答案 0 :(得分:0)

这是你想要的吗?

select     CASE WHEN `event_attendees_mapping`.`attendees_status_id` = ????
                THEN 1
                ELSE 0
           END as new_Col
FROM `event_attendees_mapping`
WHERE `event_attendees_mapping`.`event_schedule_id` = 1
  AND `event_attendees_mapping`.`employee_code` = 'TJU_741'