join关联查询

     $temp=$temp.$value[‘cityname’];

     $model=M(‘greenaction’);

thinkphp:

$subquery=M(‘greenschool’)->field(‘gs_cityid’)->group(‘gs_cityid’)->select(false);

     $temp=”;


);

    
->field(‘a.*,b.gs_schoolnamecn,b.gs_schoolnameen’)->select();

 


       dump($temp); 

  

 

  }

     $subquery=M('greenschool')->distinct(true)->field('gs_provinceid')->select(false);       $plist=M('province')->field('provinceid,provincename')->where('countryid=1 and provinceid in '.$subquery)->order('provinceid')->select();  

     $temp=”;

     $list=$model->alias(‘a’)->join(‘ LEFT JOIN tsh_greenschool b
on a.greenschoolid=b.id’)

 

     foreach ($citylist as $value) {

使用sql查询:
SELECT a.*,b.gs_schoolnamecn,b.gs_schoolnameen FROM tsh_greenaction
a  LEFT JOIN tsh_greenschool b on a.greenschoolid=b.id 

SELECT provinceid,provincename from tsh_province where provinceid in(

     $citylist=M(‘city’)->field(‘cityid,cityname’)->where(‘cityid
in ‘.$subquery)->select();

  $temp=$temp.$list[$i][‘gs_schoolnamecn’].’,’;

 $subquery=M(‘greenschool’)->field(‘gs_provinceid’)->group(‘gs_provinceid’)->select(false);

 

  for($i=0;$i<count($list);$i++){

SELECT DISTINCT gs_provinceid from tsh_greenschool)

select cityid,cityname from tsh_city where cityid in(

  使用thinkphp连贯操作:

实现一条语句:

select gs_cityid from tsh_greenschool group by gs_cityid 

 

 

     }


$result=M(‘province’)->fetchSql(true)->field(‘provinceid,provincename’)->where(‘provinceid
in ‘.$subquery)->select();

sql:

thinkphp:      

     dump($temp);