TP框架 mysql子查询

一些比较复杂的业务关系,用子查询解决. 比循环便利要好的多哈.

比如下面这句 select 和where in 语句都用了子查询. 因为父查询在select里,所以用了select的字段当子查询的条件.

这块也是凭感觉写, 返回的值如果在select里,只能是1row,否则会报错.

 这里都是凭感觉在写,经验就是多想,多写,多试验...

M('Product')->alias('p')
->field('p.*,t.* , (select GROUP_CONCAT(crm_pgkkxo) from 5kcrm_customer c where c.customer_id in (select cid from 5kcrm_cprelation cp where cp.pid = product_id group by pid) ) customer_names ')
->join('left join 5kcrm_teacher t ON t.tid = p.teacher')
->where($map)
->select();

原文地址:https://www.cnblogs.com/jinshuo/p/8378133.html