tp5 子查询统计另一张表的长度

子查询统计另一张表的长度


$subQuery= Db::table('adv')->alias('adv')

->field('count(adv.ap_id)')

->where('adv.ap_id=adp.ap_id')

->buildSql();

$list= Db::table('adv_position')->alias('adp')

->field("adp.*,$subQuery as img_count")

->where($condition)

->select();


生成的sql语句
SELECT

adp.ap_id, (

SELECT

count(adv.ap_id)

FROM

adv AS adv

WHERE

adv.ap_id = adp.ap_id

) AS img_count

FROM

adv_position AS adp;


你可能感兴趣的:(tp5 子查询统计另一张表的长度)