sqlplus中
select * from chaowei where riqi in(select min(riqi) from chaowei 
where riqi between '2008-09-01 09:12' and '2008-09-27 09:12' 
Group By substr(riqi,0,15)) order by riqi asc;
结果:
   BIANHAO ZHANDIANID RIQI                              D1 RECORDRIQI
---------- ---------- ------------------------- ---------- -------------------------
         4        481 2008-09-20   16:50:02            6.7 2008-09-20   16:50:02
         7        481 2008-09-20   18:09:38            3.8 2008-09-20   18:09:38
        10        481 2008-09-20   19:00:08            4.7 2008-09-20   19:00:08
        24        481 2008-09-20   20:58:35            7.8 2008-09-20   20:58:35
         1        481 2008-09-21   10:25:14            3.4 2008-09-21   10:25:14
        31        481 2008-09-23   15:24:00            5.6 2008-09-23   15:26:00
        25        481 2008-09-25   09:20:00            4.5 2008-09-25   09:22:00
        27        481 2008-09-25   15:06:00            4.5 2008-09-25   15:08:00
        36        481 2008-09-25   19:53:00            4.5 2008-09-25   19:55:00
        37        481 2008-09-26   14:52:00            5.8 2008-09-26   14:54:00已选择10行。
在jsp页面中
"select *  from chaowei where riqi in(select min(riqi) from chaowei where riqi between to_date('"+date1+"','yyyy-mm-dd hh24:mi') and to_date('"+date2+"','yyyy-mm-dd hh24:mi') Group By substr(riqi,0,15)) order by riqi asc";date1,date2分别对应上面两个时间
结果:
          4        481 2008-09-20   16:50:02            6.7 2008-09-20   16:50:02
         1        481 2008-09-21   10:25:14            3.4 2008-09-21   10:25:14
        31        481 2008-09-23   15:24:00            5.6 2008-09-23   15:26:00
        25        481 2008-09-25   09:20:00            4.5 2008-09-25   09:22:00
        37        481 2008-09-26   14:52:00            5.8 2008-09-26   14:54:00为什么得到的结果不一样呢?怎么修改两者才能一致?

解决方案 »

  1.   

    注意不是'yyyy-mm-dd hh24:mi',而是'yyyy-mm-dd hh24:mi:ss'
      

  2.   

    你的riqi列的类型应该不是date型的 而是string型的吧 你的jsp里面的sql写的riqi是date型,我估计问题就出在这
      

  3.   

    在jsp页面中 
    "select *  from chaowei where riqi in(select min(riqi) from chaowei where riqi between to_date('"+date1+"','yyyy-mm-dd hh24:mi') and to_date('"+date2+"','yyyy-mm-dd hh24:mi') Group By substr(riqi,0,15)) order by riqi asc";
    我把substr(riqi,0,15)中的15改成1,只查到一条记录,改成>2的任何数得到的都是
    结果: 
              4        481 2008-09-20  16:50:02            6.7 2008-09-20  16:50:02 
            1        481 2008-09-21  10:25:14            3.4 2008-09-21  10:25:14 
            31        481 2008-09-23  15:24:00            5.6 2008-09-23  15:26:00 
            25        481 2008-09-25  09:20:00            4.5 2008-09-25  09:22:00 
            37        481 2008-09-26  14:52:00            5.8 2008-09-26  14:54:00 
    郁闷,substr()不起作用了吗?快帮帮我把!