mysql 案例语句

发布于 2024-10-10 18:34:24 字数 642 浏览 1 评论 0原文

我可以在 mysql case 语句中使用“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");

或任何其他解决方案?

can i use 'AND' in the mysql case statement

for example:

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

or any other solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初相遇 2024-10-17 18:34:24

这是你需要的吗?

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

这使用搜索案例格式(文档)并省略ELSE NULL,因为无论如何这是隐式的。

Is this what you need?

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

This uses the searched case format (second one in the docs) and leaves out the ELSE NULL as this is implicit anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文