求一条mysql 的sql 文
来源:百度知道 编辑:UC知道 时间:2024/05/04 10:22:30
我想查询相应时间范围的数据,where 要怎么写
表里有3个字段,年 月 日
例如:
数据如下格式
2009 1 12//已知的第一条年月日数据
2009 2 13//已知的第二条年月日数据
。。。。。
我要取 2009-1-1 到 2009-2-1 的所有数据
y1 m1 d1//已知的第一条年月日数据
y2 m2 d2//已知的第二条年月日数据
select ... //要查询的列
form ... //表名
where year_ between y1 and y2
and month_ between m1 and m2
and day_ between d1 and d2
// 假设你的年月日的几个列分别叫
year_ month_ day_
select ... //要查询的列
form ... //表名
where year_ between y1 and y2
and month_ between m1 and m2
and day_ between d1 and d2
正解
SQLSERVER里可以这么写,开始日期@startTime,结束日期@EndTime
select * from table where 日期列 between year(@StartTime)+month(@StartTime)+'01' and year(@EndTime)+month(@EndTime)+'01'.
但是不知道MYSQL里有没有YEAR 和MONTH函数。
一个表里有3项,三项指的是3个字段吗?
结果不包括2月1日这一天吧?
select * from table1
where 年=2009 and 月=1
select * from users where date between (select date from users where id = 1) and
(select date from users where id = 2 )
这是我写的 sql 语句`.. 我users 表里有3列数据 id ,date , name
我是查其中2个date之间的所有数据 . 不知道你是不