现有表,
nm_purchase
字段
id,date,cost (double类型)
现在又数据
1 2010-01-02 08:23:59 23.5
2 2010-01-02 09:23:59 24.5
3 2010-01-03 10:23:59 21.5
4 2010-01-04 11:23:59 26.5
5 2010-01-05 12:23:59 17.5
6 2010-01-06 13:23:59 20.5
现在要求取 这一(2010-01-01 到 2010-01-07)段时间中,最早的时间点和最晚的时间点的cost的差;
请各位大侠看清楚条件!谢谢了!
------解决方案--------------------
测试数据:
- SQL code
CREATE TABLE NMPurchase( ID NUMBER(3), MyDate DATE, COST NUMBER(4, 1));DELETE T190;INSERT INTO NMPurchase VALUES(1, to_date('2010-01-02 08:23:59', 'YYYY-MM-DD HH24:MI:SS'), 23.5);INSERT INTO NMPurchase VALUES(2, to_date('2010-01-02 09:23:59', 'YYYY-MM-DD HH24:MI:SS'), 24.5);INSERT INTO NMPurchase VALUES(3, to_date('2010-01-03 10:23:59', 'YYYY-MM-DD HH24:MI:SS'), 21.5);INSERT INTO NMPurchase VALUES(4, to_date('2010-01-04 11:23:59', 'YYYY-MM-DD HH24:MI:SS'), 26.5);INSERT INTO NMPurchase VALUES(5, to_date('2010-01-05 12:23:59', 'YYYY-MM-DD HH24:MI:SS'), 17.5);INSERT INTO NMPurchase VALUES(6, to_date('2010-01-06 13:23:59', 'YYYY-MM-DD HH24:MI:SS'), 20.5);
------解决方案--------------------
- SQL code
select (select max(cost) from table where date=(select max(date) from table))-(select max(cost) from table where date=(select min(date) from table)) from dual