$subQuery = M("zstar_apply_goods") ->join("LEFT JOIN shop_products ON zstar_apply_goods.ShopToken = shop_products.ShopToken") ->where($where) ->field("zstar_apply_goods.ShopToken") ->group("zstar_apply_goods.ShopToken") ->buildSql(); $result = M("zstar_apply_goods")->table($subQuery . ‘ a‘)->count();