1. 查询N条数据,取最高,最低,计算等。。。。
select max(datavalue) as maxDataValue,min(datavalue) as minDataValue,count(1) as dataSize,sum(dataValue) as sumDataValue from RT_realDataDoubleValue
查询所需要时间 0.482s
select datavalue from RT_realDataDoubleValue
查询所需要时间 0.431,但是考虑到查询得到的结果, 需要做计算,则 选择第一种查询 更为节省时间
2.关于 to_char(date,'yyyy-mm-dd hh24:mi:ss') = ‘2020-05-28 13:00:00’ 与 date=to_date(‘2020-05-28 13:00:00’,'yyyy-mm-dd hh24:mi:ss') 耗时比较:
SQL 如下:
第一种: to_char(date,'yyyy-mm-dd hh24:mi:ss') = ‘2020-05-28 13:00:00’
select a.datavalue-b.datavalue as datavalue from
(select sum(datavalue) as datavalue from RT_realDataDoubleValue where 1=1 and dataid='2379' and organizationid in(85,86,87) and to_char(datadate,'yyyy-mm-dd hh24:mi:ss')='2020-05-28 13:00:00') a,
(select sum(datavalue) as datavalue from RT_realDataDoubleValue where 1=1 and dataid='2379' and organizationid in(85,86,87) and to_char(datadate,'yyyy-mm-dd hh24:mi:ss')='2020-05-27 14:00:00') b
查询耗时:2.451s
第二种:date=to_date(‘2020-05-28 13:00:00’,'yyyy-mm-dd hh24:mi:ss')
select a.datavalue-b.datavalue as datavalue from
(select sum(datavalue) as datavalue from RT_realDataDoubleValue where dataid='2379' and organizationid in(85,86,87) and datadate= to_date('2020-05-28 13:00:00','yyyy-mm-dd hh24:mi:ss')
) a,
(select sum(datavalue) as datavalue from RT_realDataDoubleValue where dataid='2379' and organizationid in(85,86,87) and datadate=to_date('2020-05-27 14:00:00','yyyy-mm-dd hh24:mi:ss')) b;
耗时:0.009s
显而易见,oracle 在查询是, 时间格式化,to_char 比 to_date 耗时更长