<?php$con = mysql_connect("127.0.0.1","root","pi2013wik") or die("Could not connect");mysql_select_db("tongji",$con);mysql_query("set name 'utf8'");$sql ="select a.name name1,a.*,b.value,b.* from piwik_site a,piwik_archive_numeric_2013_10 b where b.period in(1,2,3) and b.name='nb_visits' and a.idsite=b.idsite order by b.value desc";$res = mysql_query($sql);?>
<?phpwhile($row = mysql_fetch_array($res)){?> <tr>
<td bordercolor="#333333" bgcolor="#CCCCCC"><div align="left"><?php echo $row['name1']?></div></td> <td bordercolor="#333333" bgcolor="#CCCCCC"><div align="left"><?php echo $row['date1']?></div></td> <td bordercolor="#333333" bgcolor="#CCCCCC"><div align="left"><?php if($row['period'] == 1){echo $row['value'];}?></div></td> <td bordercolor="#333333" bgcolor="#CCCCCC"><div align="left"><?php if($row['period'] == 2){echo $row['value'];}?></div></td> <td bordercolor="#333333" bgcolor="#CCCCCC"><div align="left"><?php if($row['period'] == 3){echo $row['value'];}?></div></td> </tr> <?php }?>
以上都是都是正确的,下面是查询出来的数据
我现在想查询出来 每天的最后一个数据 每周的最后一个数据(26791) 怎么 能实现 这个SQL和输出的时候应该怎么写??高手回答!
ä¸è¬ï¼phpè°ç¨mysqlçæ¥å£æ¥è¯¢ï¼æ¥è¯¢è¯å¥å¦ä¸ï¼
select * from table order by id DESC limit 1
è¿æ ·å°±ååºè®°å½çæåä¸æ¡è®°å½ã
如果页面显示的是这个语句,那么最后一个应该是select a.name name1,a.*,b.value,b.* from piwik_site
a,piwik_archive_numeric_2013_10 b where b.period in(1,2,3) and
b.name='nb_visits' and a.idsite=b.idsite order by b.value asc limit 1
或者先执行一次select count(*) 拿到数量num,再select a.name name1,a.*,b.value,b.* from piwik_site
a,piwik_archive_numeric_2013_10 b where b.period in(1,2,3) and
b.name='nb_visits' and a.idsite=b.idsite order by b.value desc limit num-1,1
请问错在那? 应该怎么写?