1.select * from news where to_char(createtime,'yyyy-mm-dd') = '2008-5-19'
  我想到的是把to_char(createtime,'yyyy-mm-dd')建成函数索引,别的没想出来
2.select a.* from emp1 a where a.id not in (select b.id from emp2 b and b.name='roc')
  我的改法是select a.* from emp1 a left join emp2 b on a.id=b.id and b.name<>'roc'
3.select a.id,b.*,c.*,d.* from (select a.id,count(name),sum(salary) from a group by a.id) b,a,c,d
where a.id=b.id and b.id=c.id and c.id=d.id and c.name='roc'
 这道我是真的不会了

解决方案 »

  1.   

    1.select * from news where to_char(createtime,'yyyy-mm-dd') = '2008-5-19' 
      我想到的是把to_char(createtime,'yyyy-mm-dd')建成函数索引,别的没想出来 
    ==》关建索引应该不够,需要改sql,否则索引不使用
        select (各个字段名) from news where createtime = to_date('2008-5-19','yyyy-mm-dd')
        
    上面一句,我觉得顺你的思路,改了改。其他两句觉得呢,跟你具体的环境有关,比如表数据的多少。
      

  2.   

    你说的没错,因为把列放在函数中的话列上的索引就不起作用了。谢谢回答。其他两句都是数据量比较大的情况下的,那句group by最好用别的逻辑实现,但我不会。
      

  3.   

    你说的没错,因为把列放在函数中的话列上的索引就不起作用了。谢谢回答。其他两句都是数据量比较大的情况下的,那句group by最好用别的逻辑实现,但我不会。
      

  4.   

    1、where createtime>=to_date('2008-5-19','yyyy-mm-dd') and createtime<to_date('2008-5-20','yyyy-mm-dd')
    并且createtime上建索引
    2、select a.* from emp1 a where not exists (select b.id from emp2 b where b.name='roc' and b.id=a.id)
      

  5.   

    3.select a.id,b.*,c.*,d.* from (select a.id,count(name),sum(salary) from a,c where a.id=c.id and c.name='roc' group by a.id) b,a,c,d 
    where a.id=b.id and b.id=c.id and c.id=d.id  不知道这些表具体怎建的
    如果能出相同结果可以考虑一下
    直接select xxxx,country(a.xx),sum(a.xx)
    from a,b,c,d
    where xxx
    group by a.id
      

  6.   

    4楼是高手,5楼也是高手,可能我写的比较乱,我认为应该把那个group by优化一下
      

  7.   

    3.select a.id,b.*,c.*,d.* from (select a.id,count(name),sum(salary) from a group by a.id) b,a,c,d 
    where a.id=b.id and b.id=c.id and c.id=d.id and c.name='roc' 
    把c表作为一个子表将条件写在子表里面可以使最后的连接数据减少。其他的应该没什么可以优化的了。
      

  8.   


    第一句那么写不就是直接一个=就结束了么,为什么要多此一举来个>= 然后再<呢?
      

  9.   

    to_date('2008-5-19','yyyy-mm-dd')得到的是2008-5-19 0点的时间,而数据保存的日期可能是2008-05-19的任何时刻,所以要超过或等分与零点而早于下一天零点的数据才是当天全天的数据