SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for time
-- ----------------------------
CREATE TABLE `time` (
  `id` int(11) NOT NULL auto_increment,
  `object` text,
  `channel` text,
  `time` datetime default NULL,
  `count` int(11) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ----------------------------
-- Records 
-- ----------------------------
INSERT INTO `time` VALUES ('1', 'a', 'b', '2007-11-29 12:20:00', '50');
INSERT INTO `time` VALUES ('2', 'a', 'b', '2007-11-29 12:25:00', '80');
INSERT INTO `time` VALUES ('3', 'a', 'b', '2007-11-29 12:35:00', '80');
INSERT INTO `time` VALUES ('4', 'd', 'c', '2007-11-29 12:40:00', '90');以上内容应为你所提供,为方便其他人测试。
以下为现阶段测试语句.
select * from time a left join time b on b.time = DATE_ADD(a.time,INTERVAL 5 MINUTE) and a.object = b.object;

解决方案 »

  1.   

    SysTem128  条件少了,value > 50
      

  2.   

    那是次要条件,主要是时间差的问题.value现在放上去只能让结果受到干扰.select * from time a join time b on b.time = DATE_ADD(a.time,INTERVAL 5 MINUTE) and a.object = b.object and a.count>=50 and b.count>=50 ;
    搞定……:)
      

  3.   

     select * from time a join time b on b.time = DATE_ADD(a.time,INTERVAL 5 MINUTE) and a.object = b.object and a.channel = b.channel and a.count>=50 and b.count>=50 ;
    忘了渠道……
      

  4.   

    如果时间判断b.time = DATE_ADD(a.time,INTERVAL 5 MINUTE) 正确,那也没有什么难度了。楼主为什么不考虑用时间截呢。DATE_ADD(a.time,INTERVAL 5 MINUTE)这种写法第一次见到,今天算是学了一手了,呵呵。不过在pHP里面好像时间都是以time()存的。也最好那样存。
      

  5.   

    我用你的表,数据也是你的,但我用你的SQL语句搜出来为空
      

  6.   

    -_-!给出我从建表到查询的流程,自己找原因.mysql> SET FOREIGN_KEY_CHECKS=0;
    -- ----------------------------
    -- Table structure for time
    -- ----------------------------
    CREATE TABLE `time` (
      `id` int(11) NOT NULL auto_increment,
      `object` text,
      `channel` text,
      `time` datetime default NULL,
      `count` int(11) default NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ----------------------------
    -- Records 
    -- ----------------------------
    INSERT INTO `time` VALUES ('1', 'a', 'b', '2007-11-29 12:20:00', '50');
    INSERT INTO `time` VALUES ('2', 'a', 'b', '2007-11-29 12:25:00', '80');
    INSERT INTO `time` VALUES ('3', 'a', 'b', '2007-11-29 12:35:00', '80');
    INSERT INTO `time` VALUES ('4', 'd', 'c', '2007-11-29 12:40:00', '90');Query OK, 0 rows affectedQuery OK, 0 rows affectedQuery OK, 1 row affectedQuery OK, 1 row affectedQuery OK, 1 row affectedQuery OK, 1 row affectedmysql> select * from time a join time b on b.time = DATE_ADD(a.time,INTERVAL 5 MINUTE) and a.object = b.object and a.channel = b.channel and a.count>=50 and b.count>=50 ;
    +----+--------+---------+---------------------+-------+----+--------+---------+---------------------+-------+
    | id | object | channel | time                | count | id | object | channel | time                | count |
    +----+--------+---------+---------------------+-------+----+--------+---------+---------------------+-------+
    |  1 | a      | b       | 2007-11-29 12:20:00 |    50 |  2 | a      | b       | 2007-11-29 12:25:00 |    80 |
    +----+--------+---------+---------------------+-------+----+--------+---------+---------------------+-------+
    1 row in setmysql> select VERSION();+---------------+
    | VERSION()     |
    +---------------+
    | 5.0.18-nt-max |
    +---------------+
    1 row in set
      

  7.   

    -_-!!!!
    一条记录会有2个id两个time两个……么?
    如果需要提取独立的两条记录就得两条执行语句了,而且很难控制.