2

我在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

但它不工作

4

6 回答 6

8

使用YEAR()见文档)并这样做:

SELECT
  *
FROM
  table_name
WHERE
  1999 BETWEEN YEAR(born_from) AND YEAR(born_to)
于 2012-05-04T07:16:37.117 回答
2

这个怎么样:

   Select * from table_name where
    year(born_from)>=1999 AND year(born_to)<=1999
于 2012-05-04T07:14:29.620 回答
2
Select * from table_name
where born_to >= '1999-01-01' AND born_from <= '1999-12-31'

此查询与其他答案相比可能使用索引

于 2012-05-04T07:16:38.243 回答
1

试试这个

      Select * from table_name where "1999" BETWEEN YEAR(born_from) AND YEAR(born_to)
于 2012-05-04T07:16:15.930 回答
0

这是一个例子

select * from table_name where year(born_from)>1999 and year(born_to)<=1999

于 2012-05-04T07:18:50.800 回答
0

我觉得你可以用这个

Select * from table_name where "1999" BETWEEN YEAR(born_from) AND YEAR(born_to)

于 2012-05-04T07:22:16.680 回答