select * from tiezi_table where biaoti like '%a%' or nongr like '%a%' and to_days(now())-to_days(shij) > 天数 group by fu_id order by shij

解决方案 »

  1.   

    select * from tiezi_table where biaoti like '%a%' or nongr like '%a%' and shij >'2002-09-04' group by fu_id order by shij应该没有错吧 
      

  2.   

    mysql> select * from tiezi_table where biaoti like '%a%' or nongr like '%a%' and
     to_days(now())-to_days(shij) < 2 group by fu_id order by shij;
    +-----+-------+--------------------+--------------------------------------------
    --------------------------------------------------------------------------------
    ----------------------+------+-------+---------+---------------+----------------
    -----+--------+---------+---------+---------------------+--------------+--------
    -+-------+-----------+-------+
    | id  | fu_id | biaoti             | nongr                      | huif | fatie | zhiding | ip            | shij
         | userid | suoding | jinghua | shij_paix           | tiaozi_bqing | dji_shu
     | email | zhuanl_id | duanx |
    +-----+-------+--------------------+--------------------------------------------
    --------------------------------------------------------------------------------
    ----------------------+------+-------+---------+---------------+----------------
    -----+--------+---------+---------+---------------------+--------------+--------
    -+-------+-----------+-------+
    |  14 |     6 | dsfsafsds          | dfsafsdsafsasafs                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    0:58 |     10 |       0 |       0 | 2002-08-16 16:38:07 |            1 |       5
     |     0 |         1 |  NULL |
    |  15 |     7 | dsfsafsfsafsa      | sdfsasafsafsafsfsasasadsfsf
    <div align=right>[此帖在2002-08-16日21:59:36被小生编辑过]</div>
    [div][此帖在2002-08-24日9:43:45被小生编辑过][/div] |    0 |     1 |       1 | 12
    7.0.0.1     | 2002-08-16 00:31:08 |     10 |       0 |       0 | 2002-08-31 23:3
    5:46 |            1 |     248 |     0 |         1 |  NULL |
    |  16 |     8 | sfdsaffsads        | sdafasfsasasfsafsf                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    1:40 |     10 |       1 |       0 | 2002-08-16 00:31:40 |            1 |       8
     |     0 |         1 |  NULL |
    |  17 |     9 | dfsaasdsasf        | dsafsasas                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    1:51 |     10 |       0 |       0 | 2002-08-26 01:02:40 |            1 |       4
     |     0 |         1 |  NULL |
    |  18 |    10 | sdafsafsfsafsas    | sadfasassssafsdf                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    2:01 |     10 |       0 |       0 | 2002-08-29 08:49:47 |            1 |     110
     |     0 |         1 |  NULL |
    |  19 |    11 | sdafsasafssa       | dsfdsassafsafsfs                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    2:09 |     10 |       0 |       0 | 2002-08-29 19:11:02 |            1 |      12
     |     0 |         1 |  NULL |
    |  20 |    12 | sdafsasfssa        | dssafasfassafsfsa                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    2:19 |     10 |       0 |       0 | 2002-08-16 16:42:04 |            1 |       4
     |     0 |         1 |  NULL |
    |  21 |    13 | dsafsaassaf        | sdfsasadasasds                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    2:28 |     10 |       0 |       0 | 2002-08-16 16:39:35 |            1 |       2
     |     0 |         1 |  NULL |
    |  22 |    14 | dsasafs            | sdafsafafssa
    sa
    fsa
    fsa
    fsa                                |    0 |     1 |       0 | 127.0.0.1     | 2002-
    08-16 00:32:41 |     10 |       0 |       0 | 2002-08-16 16:39:47 |            1
     |       2 |     0 |         1 |  NULL |
    |  23 |    15 | dsfassafsasafsa    | dsfsafassfsa                      |    0 |     1 |       1 | 127.0.0.1     | 2002-08-16 00:3
    2:52 |     10 |       1 |       0 | 2002-08-16 16:39:25 |            1 |      41
     |     0 |         1 |  NULL |
    |  24 |    16 | sdfsafsfs          | safsafdasfsasfsa                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    3:00 |     10 |       0 |       0 | 2002-08-16 16:41:52 |            1 |       2
     |     0 |         1 |  NULL |
    |  25 |    17 | sdfsasasfdsfs      | sdfdsaasdsafsaasffaa                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    3:10 |     10 |       0 |       0 | 2002-08-25 08:31:12 |            1 |      33
     |     0 |         1 |  NULL |
    |  26 |    18 | sdfdssafadsfsa     | sadsasfas                      |    0 |     1 |       1 | 127.0.0.1     | 2002-08-16 00:3
    3:18 |     10 |       0 |       0 | 2002-08-16 16:39:14 |            1 |      16
     |     0 |         1 |  NULL |
    |  27 |    19 | sddasssa           | sadasfsf                      |    0 |     1 |       1 | 127.0.0.1     | 2002-08-16 00:3
    3:26 |     10 |       0 |       0 | 2002-08-25 01:14:09 |            1 |      67
     |     0 |         1 |  NULL |
    |  28 |    20 | sfadassa           | dsafsasad                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    3:35 |     10 |       0 |       0 | 2002-08-16 16:40:20 |            1 |       2
     |     0 |         1 |  NULL |
    |  29 |    21 | sadsaasfs          | sadsadadssa                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    3:43 |     10 |       0 |       0 | 2002-08-16 16:41:26 |            1 |       5
     |     0 |         1 |  NULL |
    |  30 |    22 | dssassa            | safdsasfsfdfsa                      |    0 |     1 |       0 | 127.0.0.1     | 2002-08-16 00:3
    3:53 |     10 |       0 |       0 | 2002-08-16 16:39:58 |            1 |       2
     |     0 |         1 |  NULL |
      

  3.   

    楼上两位的SQL语句我都查询了,可还是查询到了规定外时间的记录。。再寻求帮助。
      

  4.   

    select * from tiezi_table where (biaoti like '%a%' or nongr like '%a%') and to_days(now())-to_days(shij) > 2 group by fu_id order by shij
      

  5.   

    select * from tiezi_table where (biaoti like '%a%' or nongr like '%a%') and to_days(now())-to_days(shij) > 2 group by fu_id order by shij
      

  6.   

    能问一下吗?
    to_days是在mysql里转变成日期的东东吗?
    如果是是不是只能在mysql里用?谢了.
      

  7.   

    To  print(小生) :
    如果你要找7天之内的东西,则SQL语句应该如下:
    select * from tiezi_table where (biaoti like '%a%' or nongr like '%a%') and to_days(now())-to_days(shij) < 7 group by fu_id order by shij
    我想你可能把SQL语句的意思搞错了。
    To anziqi(安子琦):
    to_days是MYSQL里的函数,它是将给定的日期转换成实际的天数。
    TO_DAYS(date) 
    Given a date date, returns a daynumber (the number of days since year 0): 
    mysql> select TO_DAYS(950501);
            -> 728779
    mysql> select TO_DAYS('1997-10-07');
            -> 729669
      

  8.   

    还有一个不好意思.就是group by fu_id 这个东东我一直不太明白是什么意思.
    真对不起我不别开一贴子.
      

  9.   

    谢谢 phpteam(George) ,
    那有MYSQL的函数介绍呢?我只有本SQL的书籍,对于MYSQL介绍极少。。to:anziqi(安子琦) 
    group by fu_id 是查询数据库的记录如果fu_id字段有相同的值的记录的话只显示fu_id字段相同记录的其中一条,呵呵  我是这么理解的不知道会不会误人子弟,高手来指点吧。
      

  10.   

    RSEvent.Source = "SELECT * FROM activity where act_time >= '2002-01-01'" ;RSEvent.Source = "SELECT * FROM activity where act_time >= #2002-01-01#" ;RSEvent.Source = "SELECT * FROM activity where act_time >= 2002101";
    RSEvent.Source = "SELECT * FROM activity where act_time >= '2002101'";
    以上语句在 asp和 JavaScript中都是错误的,如何解决????