这个sql语句用thinkphp3.1.2的语法怎么串联在一起?

(select a.log_id,create_date,content,creator,belong_to_user,a.customer_code,follow_up_way from gs_log a left join gs_customer b on a.customer_code=b.customer_code where b.customer_id='35926') union (select a.log_id,create_date,content,creator,belong_to_user,('') as customer_code,follow_up_way from gs_log a left join gs_r_customer_log b on a.log_id=b.log_id where b.customer_id='35926') limit 5,5

我写的:

 $log_join = "left join __CUSTOMER__ b  on a.customer_code = b.customer_code";
            $log_data = M('log')->alias('a')->where("b.customer_code != '' AND b.customer_id = $customer_id")->join
                ($log_join)->field("a.log_id,create_date,content,creator,belong_to_user,a.customer_code,follow_up_way")
                ->union("SELECT a.log_id,create_date,content,creator,belong_to_user,a.customer_code,follow_up_way FROM gs_log a left join gs_customer b on a.customer_code = b.customer_code WHERE ( b.customer_code != '' AND b.customer_id = $customer_id )")
                ->select();

没有串联起来

阅读 2.1k
1 个回答

就写原生的吧 效率还高点 用query()方法

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题