thinkphp5数据库操作中field的问题

代码:

$result = Db::table('edu_student_contract_agreement')
            ->alias('a')
            ->field("a.id, c.name AS product_name, b.agreement_number, IF(g.student_contract_agreement_id IS NULL, '', g.receipt_numbers) AS receipt_numbers, 1 AS buy_cnt, d.product_standard_price, d.product_lowest_price, IF(e.name IS NULL, ' ', e.name) AS class_name, IF(f.sum_teach_hour IS NULL, '0', f.sum_teach_hour) AS sum_teach_hour, c.periods")
            ->join('edu_student_contract b', 'a.student_contract_id = b.id','LEFT')
            ->join('edu_product c', 'a.product_id = c.id','LEFT')
            ->join('edu_product_price d', 'a.product_price_id = d.id','LEFT')
            ->join('edu_class e', 'a.class_id = e.id','LEFT')
            ->join([$t_sql=> 'f'], 'a.student_id = f.student_id AND a.class_id = f.class_id','LEFT')
            ->join([$t2_sql=> 'g'], 'a.id = g.student_contract_agreement_id','LEFT')
            ->where(['a.id'=>['in', $student_contract_agreement_ids]])
            ->order("a.id ASC")
            ->select();

注:多个if判断时,不能有相同的值(如第一个为‘’则第二个if中不能出现‘’,可写成‘ ’,中间加个空格)

posted @ 2019-01-17 13:48  卖萌的猴子  阅读(2327)  评论(0编辑  收藏  举报