第一次 $thissql="create temporary table tmp select max(id) as id from yxxl where sh='2' group by wllb "; $query=mysql_query($thissql); 底二次 $thissql="select yxxl.* from yxxl,tmp where yxxl.id=tmp.id"; $query=mysql_query($thissql);结果已得到
就一个联合查询就可以了: $sql="select a.* from yxx1 as a join (select max(id) as id from yxx1 where sh='2' group by wllb)as b on a.id=b.id";或者: $sql="select a.* from yxx1 id id(select max(id) as id from yxx1 where sh='2' group by wllb)
搞定了,谢谢大家! 先合并,在拆解 $thissql="SELECT SUBSTRING_INDEX(Max(CONCAT_WS(',', id, wlmc) ), ',', 1) as id, SUBSTRING_INDEX(max(CONCAT_WS(',', id, wlmc) ), ',', -1) as wlmc FROM yxxl where sh='2' GROUP BY wllb";
$thissql="create temporary table tmp select max(id) as id from yxxl where sh='2' group by wllb ";
$query=mysql_query($thissql);
底二次
$thissql="select yxxl.* from yxxl,tmp where yxxl.id=tmp.id";
$query=mysql_query($thissql);结果已得到
$sql="select a.* from yxx1 as a join (select max(id) as id from yxx1 where sh='2' group by wllb)as b on a.id=b.id";或者: $sql="select a.* from yxx1 id id(select max(id) as id from yxx1 where sh='2' group by wllb)
先合并,在拆解
$thissql="SELECT SUBSTRING_INDEX(Max(CONCAT_WS(',', id, wlmc) ), ',', 1) as id, SUBSTRING_INDEX(max(CONCAT_WS(',', id, wlmc) ), ',', -1) as wlmc FROM yxxl where sh='2' GROUP BY wllb";
不敢独享,送给大家http://www.phpe.net/mysql_manual/06-3.html#IDX1187