这东西能用子查询查出来吗?

zhu6100441 2014-02-11 04:59:56
现在有表结构及数据如下:

id date number
1 2012-07-12 17:05:15 10
2 2012-07-12 18:12:15 12
3 2012-07-12 19:17:15 10
4 2012-07-12 20:26:15 19
5 2012-07-13 17:05:15 5
6 2012-07-13 18:05:15 12
7 2012-07-13 19:26:15 18
8 2012-07-13 20:29:15 23
9 2012-07-13 21:33:15 15

现在我想求12年7月份18点到20点的number总和,能用一条sql语句写出来么?需要几个子查询?求各位大神给小弟指点指点!
...全文
171 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
流浪川 2014-02-12
  • 打赏
  • 举报
回复
12年7月份18点到20点的number总和 建议使用to_char实现 to_char(date,'yyyy-mm')='2012-07' to_char(date,'hh24')>=18 and to_char(date,'hh24')<=20 即:

select sum(number) from 表名 where to_char(date,'yyyy-mm')='2012-07' and 
to_char(date,'hh24')>=18 and to_char(date,'hh24')<=20
-江沐风- 2014-02-12
  • 打赏
  • 举报
回复
引用 4 楼 lu010610 的回复:
[quote=引用 3 楼 u012724379 的回复:] [quote=引用 2 楼 lu010610 的回复:] select sum(number) from t where to_number(to_char(date,'yyyymmhh24')) between 20120718 and 20120720
楼上时间好像有点问题![/quote]什么问题?[/quote] 哈哈,是没有问题!
wushangjimo 2014-02-12
  • 打赏
  • 举报
回复
引用 4 楼 lu010610 的回复:
[quote=引用 3 楼 u012724379 的回复:] [quote=引用 2 楼 lu010610 的回复:] select sum(number) from t where to_number(to_char(date,'yyyymmhh24')) between 20120718 and 20120720
楼上时间好像有点问题![/quote]什么问题?[/quote] 木有问题
_拙计 2014-02-12
  • 打赏
  • 举报
回复
引用 3 楼 u012724379 的回复:
[quote=引用 2 楼 lu010610 的回复:] select sum(number) from t where to_number(to_char(date,'yyyymmhh24')) between 20120718 and 20120720
楼上时间好像有点问题![/quote]什么问题?
-江沐风- 2014-02-11
  • 打赏
  • 举报
回复
引用 2 楼 lu010610 的回复:
select sum(number) from t where to_number(to_char(date,'yyyymmhh24')) between 20120718 and 20120720
楼上时间好像有点问题!
_拙计 2014-02-11
  • 打赏
  • 举报
回复
select sum(number) from t where to_number(to_char(date,'yyyymmhh24')) between 20120718 and 20120720
_拙计 2014-02-11
  • 打赏
  • 举报
回复
select sum(number) from t where to_number(to_char(date,'yyyymmhh24')) between 20120718 and 20120720

17,140

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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