我有一张包含一些数据的表格。它看起来像是:
MariaDB [lokatnik]> SELECT id_elixir, start_time FROM elixir ORDER BY start_time ASC;
+-----------+------------+
| id_elixir | start_time |
+-----------+------------+
| 3 | 00:00:00 |
| 1 | 12:30:00 |
| 2 | 13:30:00 |
+-----------+------------+
3 rows in set (0.00 sec)
现在,我需要准确选择一行匹配时间条件 - 比如 - start_time> some_time。
例如:
如何使用SQL(和MySQL / MariaDB DBMS)获取此行?
答案 0 :(得分:0)
也许,这样的事情对你有用:
SELECT
*
FROM
elixir
WHERE
CASE
WHEN start_time BETWEEN CAST('10:00:00' AS TIME) AND CAST('13:00:00' AS
TIME)
THEN id =1
WHEN start_time BETWEEN CAST('13:00:00' AS TIME) AND CAST('14:00:00' AS
TIME)
THEN id =2
WHEN start_time > CAST('14:00:00' AS TIME)
THEN id =3
ELSE true
但你可以通过使用简单的布尔运算符来实际检查:
SELECT
*
FROM
elixir
WHERE
(
start_time BETWEEN CAST('10:00:00' AS TIME) AND CAST('13:00:00' AS TIME)
AND id =1
)
OR
(
start_time BETWEEN CAST('13:00:00' AS TIME) AND CAST('14:00:00' AS TIME)
AND id =2
)
OR
(
start_time > CAST('14:00:00' AS TIME)
AND id =3