MySQL支持对datetime类型进行区间查询吗?

thewallhz 2011-07-08 03:03:18
如对 2009-11-1 00:00:15 至 2009-11-05 12:12:11 的区间进行查询,
对应的sql语句是什么?
...全文
5966 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
fmj 2011-10-21
  • 打赏
  • 举报
回复
select month(制单日期),count(*) from t group by month(制单日期)
select month(制单日期),制单日期 from t where month(制单日期) > 10
以上两语句都没有问题啊
ijustdoit168 2011-10-20
  • 打赏
  • 举报
回复
谢谢!
zl3450341 2011-07-15
  • 打赏
  • 举报
回复
哎,又只能来接点分了
ACMAIN_CHM 2011-07-14
  • 打赏
  • 举报
回复
select year(register_time) as y from user where year(register_time) >2005
thewallhz 2011-07-14
  • 打赏
  • 举报
回复
select year(register_time) as y from user 正常允许

select year(register_time) as y from user where y>2005 运行报错
错误信息如下所示:
ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ERROR 1054 : Unknown column 'y' in 'where clause'' at line 1

这是怎么回事?
thewallhz 2011-07-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wwwwb 的回复:]

字段类型是什么,如果是DATETIME
SELECT * FROM TT WHERE F1 BETWEEN '2009-11-1 00:00:15' AND '2009-11-05 12:12:11'
[/Quote]
如果在where 子句中包含 datetime类型,是否允许在 where 子句中使用MySQL日期函数,好像是不可以的,为什么?

如 where year(F) > 2003 这样的操作要报错,MySQL这种语法真的不支持么?
fellatioyzx 2011-07-13
  • 打赏
  • 举报
回复
分组的时候用year和month函数了,前面被select的项里就不能填reg_data了,如果出现非集计项目的话,该项目必须是group by后面的项目,不然类似'2000/01/01'和'2000/01/03'在分组上会歧义吧。
lanbaibai 2011-07-10
  • 打赏
  • 举报
回复
group by left(reg_data,7)
thewallhz 2011-07-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 acmain_chm 的回复:]

group by date_format(reg_data,'%Y%n)
[/Quote]
group by year(reg_data), month(reg_data)的效果和group by date_format(reg_data,'%Y%m')是一样的?
ACMAIN_CHM 2011-07-09
  • 打赏
  • 举报
回复
group by date_format(reg_data,'%Y%n)
thewallhz 2011-07-09
  • 打赏
  • 举报
回复
select count(*), reg_date from tablename group by month(reg_data),
显示的结果好像不对,怎么回事?
thewallhz 2011-07-09
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 rucypli 的回复:]

只支持to_day year两个函数分区
[/Quote]
没有to_day, 这个函数,但是有month和year这两个函数:)
rucypli 2011-07-09
  • 打赏
  • 举报
回复
只支持to_day year两个函数分区
thewallhz 2011-07-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wwwwb 的回复:]

字段类型是什么,如果是DATETIME
SELECT * FROM TT WHERE F1 BETWEEN '2009-11-1 00:00:15' AND '2009-11-05 12:12:11'
[/Quote]
select count(*) from table_name group by 月份
如何对datetime类型进行按月份的group统计操作呢?
求相应的SQL语句:)
wwwwb 2011-07-08
  • 打赏
  • 举报
回复
字段类型是什么,如果是DATETIME
SELECT * FROM TT WHERE F1 BETWEEN '2009-11-1 00:00:15' AND '2009-11-05 12:12:11'

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧