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