我在mysql中有这样的日期格式列表
--------------------------
born_form | born_to
--------------------------
1994-10-04 | 2012-05-13
1987-05-03 | 2010-03-25
我只输入1999年
我正在使用sql查询
Select * from table_name where
"1999" BETWEEN born_from AND born_to
但它不起作用
答案 0 :(得分:8)
使用YEAR()
(see documentation)并按照以下方式执行操作:
SELECT
*
FROM
table_name
WHERE
1999 BETWEEN YEAR(born_from) AND YEAR(born_to)
答案 1 :(得分:2)
这个怎么样:
Select * from table_name where
year(born_from)>=1999 AND year(born_to)<=1999
答案 2 :(得分:2)
Select * from table_name
where born_to >= '1999-01-01' AND born_from <= '1999-12-31'
此查询与其他答案进行比较可能使用索引
答案 3 :(得分:1)
试试这个
Select * from table_name where "1999" BETWEEN YEAR(born_from) AND YEAR(born_to)
答案 4 :(得分:0)
这是一个example
从table_name中选择*年份(born_from)&gt; 1999年和年份(born_to)&lt; = 1999
答案 5 :(得分:0)
我认为你可以使用它,
从table_name中选择* “1999”年度(born_from)和年份(born_to)