我有一sql语句:
    select * from table1 where date(selltime) = '2008-12-01' 查询不到数据,但是用
  select * from table1 where trim(date(selltime)) = '2008-12-01' 却能查询出来需要数据
  有谁能告诉我原因。
环境:
  linux redhat
    mysql 5.0.45-community

解决方案 »

  1.   

    selltime
    null
    2008-12-01
    2008-12-02
    2008-12-03
      

  2.   

    try:
    select * from table1 where date(ifnull(selltime,selltime,'2008-1-1')) = '2008-12-01'
      

  3.   

    纠正:
    select * from tt2 where date(ifnull(selltime,'2008-1-1')) = '2008-12-01'
      

  4.   

    其实问题刚刚找到,如果没有null值,用date函数就没有问题。如果有null值,符合条件的结果在null值前面就能查出来,在null值后面的就查询不出来,不知道是什么原因
      

  5.   

    问题我已经解决了,用trim(date(selltime))='2008-01-01'就行了。
      

  6.   

    你用
    select *,date(selltime),trim(date(selltime)) from tt2
    看看结果就知道了
      

  7.   

    结果是一样的啊,主是原因是null
      

  8.   

    Tell us your table's structure and the key distribution.
      

  9.   

    CREATE TABLE `table1` (
      `id` int(11) NOT NULL,  
      `selltime` datetime default NULL,  
      PRIMARY KEY  (`id`)  
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
      

  10.   

    用你上述代码建立表,插入上述数据,用
    select * from table1 where date(selltime) = '2008-12-01'
    可以查询出来数据。MYSQL 5.1.17
      

  11.   

    SELTIME是DATETIME型,检查记录中是否有TIME?