<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                需求:兩個數據庫中有兩個不相關的表,我需要將它們合并,并在order2中新增不存在的product_name字段,并賦予默認值 先篩選要的的值,再合并 ``` $product_name = '默認值'; $news = DB::table("guild_data_log.user_login_202206") ->where('device_id', '0001592f6d71d20cad65bcc44c3497af') ->selectRaw('product_name, login_time, device_id') ->orderBy('login_time', 'desc'); $res = Db::table('guild_data_log.user_login_202207') ->where('device_id', 'aac87e997ac499712bbf2411202f2236') ->selectRaw('IFNULL(null, ?) as product_name, login_time, device_id', [$product_name]) ->orderBy('login_time', 'desc') ->union($news) ->paginate(10); ``` 大致原生sql ``` (select login_time, device_id from `guild_data_log`.`user_login_202207` where `device_id` = '01xx' order by `login_time` desc) union (select login_time, device_id from `guild_data_log`.`user_login_202206` where `device_id` = 'c8xx' order by `login_time` desc) limit 10 offset 0 ``` 先合并,再篩選要的值 ``` // 獲取原生sql public function getBindingsSql($modObj) { $bindings = $modObj->getBindings(); $sql = str_replace('?', "'%s'", $modObj->toSql()); $sql = sprintf($sql, ...$bindings); return $sql; } public function test(){ $table = DB::table('guild_data_log.user_login_202206 as ul') ->selectRaw($selectRaw) ->where('device_id','0001592f6d71d20cad65bcc44c3497af') ->orWhere('device_id', 'aac87e997ac499712bbf2411202f2236'); // unionAllg不去重 $table->unionAll(DB::table('guild_data_log.user_login_202207 as ul') ->selectRaw($selectRaw) ->where('device_id','0001592f6d71d20cad65bcc44c3497af') ->orWhere('device_id', 'aac87e997ac499712bbf2411202f2236') ); $todayDataDetails = DB::table(DB::raw('(' . $this->getBindingsSql($table) . ') as ul')) ->selectRaw('max(ul.login_time) as last_login_time, ul.device_id') ->groupByRaw('ul.device_id') ->get(); } ``` 原生sql ``` select max(ul.login_time) as last_login_time, ul.device_id from ( (select ul.login_time, ul.device_id from `guild_data_log`.`user_login_202206` as `ul` where `device_id` = '0001592f6d71d20cad65bcc44c3497af' or `device_id` = 'aac87e997ac499712bbf2411202f2236') union all (select ul.login_time, ul.device_id from `guild_data_log`.`user_login_202207` as `ul` where `device_id` = '0001592f6d71d20cad65bcc44c3497af' or `device_id` = 'aac87e997ac499712bbf2411202f2236') ) as ul GROUP BY device_id ``` ps:記得兩個表的字段要一一對應,不可以一邊多一邊少,也不可以換位置
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看