oracle 中查询最近的一天的时间 。
我的解决法案是对时间排序 , 可是我在一想要是排序的话, 那时间的分,秒都排序了 ,可我是要按天排序取最上面的一条 。
求 : SQL 语句 。
跪求 。 。 。 大神指点。
我的解决法案是对时间排序 , 可是我在一想要是排序的话, 那时间的分,秒都排序了 ,可我是要按天排序取最上面的一条 。
求 : SQL 语句 。
跪求 。 。 。 大神指点。
解决方案 »
- 数据采集后页面显示怎么样保存那些临时的数据?怎么样效率最高呀?
- eWebEditor怎么没有图片上传,只有网络图片地址
- 关于webservice 100分在线等
- struts2中s:iterator的用法疑问?
- 呵呵! struts 有两个<logic:iterate> 输出纪录这么难呀?
- Spring+quartz 定时器 首次执行调用两次任务,怎么解决?
- 新手提问:Hashtable是做什么用的?基本用法都有哪些!谢了!
- 中文乱码,急待解决
- 怎样删除Cookie??
- 定时任务quartz,求思路
- byte数组转成String再转成byte数组
- 求高手帮助! jfreechart趋势图断裂问题
查询的时候 用replace(time,':','')
Select * From 表
Where to_char(时间, 'YYYYMMDD') = '20120101'
表 : table ,列 : money , time 时间的格式是 : 2012-09-04 16:16:50 。
select money from table where to_char(time,'yyyymmdd') = (select to_char(max(time),'yyyymmdd') from table)
)或者select d,m from (
select t.*, rownum rn from (
select to_char(time,'yyyymmdd') d,sum(money) m from table group by to_char(time,'yyyymmdd') order by to_char(time,'yyyymmdd') desc
) t
) where rn <= 1
select sum(money) from table where to_char(time,'yyyymmdd') = (select to_char(max(time),'yyyymmdd') from table)
以时间作为条件的时候,尽量不要使用 to_char 尽量用 date类型进行比较因为 字符比较使用字典序 效率不说 还有可能出现 范围不符的问题