数据库day有2个字段表示时间
month:year-month 如:2008-05
date:day 如:12
现在我要select *某年某月某日以后,某年某月某日以前的数据,请问这个SQL怎么写啊?

解决方案 »

  1.   

    字段类型?如为日期型
    select * from tt where year(字段)=2008 and month(字段)=5 and day(字段)<=10
      

  2.   

    select *
    from yourtable
    where concat(`year-month`,'-',`day`) between '2008-01-20' and '2008-02-19'
        [align=center]====  ====
    [/align]
      

  3.   

    可以按楼上的试一下,不过具体还是要看你字段类型及数据样本,比如你的day字段是数字还是文本? 如果是文本是03还是3 ?能把问题提清楚不是件容易的事.
        [align=center]====  ====
    [/align]
      

  4.   

    /*Column Information For - month*/
    ------------------------------------------Field    Type              Collation       Null    Key     Default  Extra                               
    -------  ----------------  --------------  ------  ------  -------  -------------- 
    id       int(10) unsigned  (NULL)          NO      PRI     (NULL)   auto_increment         
    userid   int(20)           (NULL)          NO              0                                
    month    varchar(8)        gbk_chinese_ci  NO                                               
    date     varchar(4)        gbk_chinese_ci  NO                                               
    dateall  int(4)            (NULL)          NO              0                                
    dateip   int(4)            (NULL)          NO              0                                
                                               
    不好意思,没把问题提清楚,这个是表结构
    month里的数据是如 2008-01  这样的
    date里的是 01  这样的
      

  5.   

    select * from yourtable
    where concat(`month`,'-',`date`) between '2008-01-20' and '2008-02-19';这样就行了。
        [align=center]====  ====
    [/align]