2011-01-04 15 views
1

kann ich mit 'AND' in der mysql case-Anweisungmysql case-Anweisung

zum Beispiel:

$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"); 

oder jede andere Lösung?

Antwort

3

Ist das, was Sie brauchen?

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

Dies verwendet das searched Fall Format (zweite in the docs) auslässt und die ELSE NULL da dies ohnehin implizit ist.

+0

habe es gerade versucht. Es hat nicht funktioniert. irgendeine andere Idee? – tonoslfx

+0

Sie müssen erklären, was Sie dann tun möchten. Einen Quellcode zu geben, der nicht ohne Erklärung funktioniert und uns Ihre Absicht abschätzen lässt, ist wahrscheinlich nicht der produktivste Ansatz! –

+0

MAX (CASE WENN b.id_beautician = 2 UND b.date_book = '$ search_date' DANN 'gebucht' END) AS thera_b – tonoslfx