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中不能出现‘’,可写成‘ ’,中间加个空格)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM