mysql案例陈述

时间:2011-01-04 16:41:08

标签: php mysql case

我可以在mysql案例陈述中使用'AND'

例如:

$d = $mysqli->query("SELECT id_timeslot, date_book, id_beautician

     ,coalesce(thera_b, 'available') AS thera_b

    FROM ( SELECT t.id_timeslot, p.id_beautician, b.date_book

    , MAX(CASE b.id_beautician WHEN 2 THEN 'booked' THEN 'booked' ELSE NULL END 
       AND 
       CASE b.date_book WHEN '2011-01-04' THEN 'booked' ELSE NULL END) AS thera_b

    FROM timeslot as t
    LEFT JOIN bookslot as b ON b.id_timeslot = t.id_timeslot
    LEFT JOIN beautician as p ON p.id_beautician = b.id_beautician
        GROUP BY t.id_timeslot) AS xx");

或任何其他解决方案?

1 个答案:

答案 0 :(得分:3)

这是你需要的吗?

MAX(CASE WHEN b.id_beautician =2 
   AND b.date_book = '2011-01-04' THEN 'booked' END )  AS thera_b

这会使用searched案例格式(the docs中的第二个案例格式)并遗漏ELSE NULL,因为这是隐含的。