php  mysql数据库找出最近相同内容的字段,用它们的id相减输出差
表mydb1、字段:(id、期数、号码1、号码2、号码3),每期开奖号有三个数字(如356)。其中的3是(号码1字段)、5是(号码2字段)、6是(号码3字段)。等到n期后开奖号又出现356时就用这次356的id减去前一次356的id输出差。
$array = array();
while($row = mysql_fetch_assoc($result)){    
if(in_array($row['content'],$array)){        
$a = $row['id'];        
foreach($array as $key =>$content){            
if($row['content']==$content){                
$b = $key;}}}else{        
$array[$row['id']] = $row['content'];}}
求各位高手详细写一写, 谢谢              
                                    php                    mysql                                                  分享到:                                                
------解决方案--------------------
select (t2.id - t1.id)from table1 t1,table2 t2 where t1.num1=t2.num1 and t1.num2=t2.num2 and t1.num3=t2.num3
------解决方案--------------------
select a.id, a.id - b.id as sub
  from mydb1 a, mydb1 b
  where a.号码1 = b.号码1
    and a.号码2 = b.号码2
    and a.号码3 = b.号码3
  having sub >0
   
 
   