您好,欢迎访问一九零五行业门户网

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'];}}
求各位高手详细写一写, 谢谢
回复讨论(解决方案) 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
麻烦再详细点呗
这样写对吗?怎么输出哇?
$result = mysql_query(select a.id, a.id - b.id from mydb1 a, mydb1 b where a.hao1 = b.hao1  && a.hao2 = b.hao2  && a.hao3 = b.hao3 having sub >0);
while($row = mysql_fetch_array($r1))
  {
  echo $row['']
其它类似信息

推荐信息