我有这个问题:
SELECT *,
CASE
WHEN ___Bookings.BOO_DateCI = '2017-04-15' THEN "In Arrival"
WHEN ___Bookings.BOO_DateCO = '2017-04-15' THEN "In Departure"
WHEN '2017-04-15' > ___Bookings.BOO_DateCI AND '2017-04-15' < ___Bookings.BOO_DateCO THEN "In House"
END AS BOO_BookingStatus
FROM ___Bookings
我如何具体说明BOO_BookingStatus
== NULL
时我不想要该行?
感谢。
答案 0 :(得分:0)
最简单的方法是将其包装在另一个查询中并定义条件:
SELECT *
FROM
(SELECT *,
CASE
WHEN ___Bookings.BOO_DateCI = '2017-04-15' THEN "In Arrival"
WHEN ___Bookings.BOO_DateCO = '2017-04-15' THEN "In Departure"
WHEN '2017-04-15' > ___Bookings.BOO_DateCI
AND '2017-04-15' < ___Bookings.BOO_DateCO THEN "In House"
END AS BOO_BookingStatus
FROM ___Bookings) AS bookings_query
WHERE bookings_query.BOO_BookingStatus IS NOT NULL;
或明确排除您的CASE
语句将返回null的所有情况:
SELECT *,
CASE
WHEN ___Bookings.BOO_DateCI = '2017-04-15' THEN "In Arrival"
WHEN ___Bookings.BOO_DateCO = '2017-04-15' THEN "In Departure"
WHEN '2017-04-15' > ___Bookings.BOO_DateCI
AND '2017-04-15' < ___Bookings.BOO_DateCO THEN "In House"
END AS BOO_BookingStatus
FROM ___Bookings
WHERE ___Bookings.BOO_DateCI = '2017-04-15'
OR ___Bookings.BOO_DateCO = '2017-04-15'
OR ('2017-04-15' > ___Bookings.BOO_DateCI
AND '2017-04-15' < ___Bookings.BOO_DateCO)