【php – 左连接计数忽略左表列从计数】教程文章相关的互联网学习教程文章

sql左连接有疑问,为什么查出来都是null,而不是没有数据?

sql左连接有疑问,为什么查出来都是null,而不是没有数据?domain是域名表,domain_sell是上架的域名表,domain_auction_history 是域名拍卖表这是我的查询语句:SELECT d.,s.,MAX(h.price) AS max_price FROM domain d LEFT JOIN domain_sell s USING(domain_id) LEFT JOIN domain_auction_history h USING(domain_id) WHERE d.status IN(已上架, 拍卖中) AND s.type=在线拍卖 ORDER BY max_price DESC LIMIT 16这是结果(应该是...

函数模拟数组上的左连接在PHP中无法正常工作【代码】

我有两个这样的数组:$left = [['UserID' => 6835406],['UserID' => 8418097], ];$right = [['Amount' => 0.00, 'UserID' => 6835406],['Amount' => 0.00, 'UserID' => 8418097] ];我正在使用此函数基于UserID feild对数组执行左连接:function left_join_array($left, $right, $left_join_on, $right_join_on = NULL){$final= array();if(empty($right_join_on))$right_join_on = $left_join_on;foreach($left AS $k => $v){$fina...

php – Laravel:左连接查询【代码】

我有这样的SQL查询,工作正常:SELECT A.program_id FROM A LEFT JOIN B ON A.program_id = B.program_id WHERE B.program_id IS NULL但我希望它重写为LARAVEL样式,如下所示:\DB::table('A') ->join('B', 'A.program_id', '=', 'B.program_id') ->select('A.program_id') ->whereNull('B.program_id') ->get()->toArray();但是这段代码返回0结果.解决方法:您正在使用join而不是left join 尝试这个\DB::table('A') ->leftjoin('B', ...

php – laravel中的未定义变量左连接【代码】

在我的情况下,我想显示每个用户完成的用户和订单,订单有状态我从输入表单获得$status这是我的代码$orders = DB::table('user_profiles')->leftJoin('orders', function($join){$join->on('user_profiles.id','=','orders.id_user')->where('orders.status','=',$status);})->selectRaw('user_profiles.*, count(orders.id_user) as order_try_count')->groupBy('user_profiles.id')->orderBy('order_try_count',$order)->paginate(...

php – Yii2 – 在多个条件下左连接【代码】

我有三张表,关系如下,------- 1 0..* ------------|Product|-------------|Availability|------- ------------1 ||1 |--------|MetaData|--------我的原始SQL看起来像这样SELECT p.ID FROM product p LEFT JOIN availability a ON a.productID=p.ID AND a.start>=DATE_ADD(DATE(now()), INTERVAL 7 DAY) LEFT JOIN meta_data m ON m.ID=p.meta_dataID WHERE a.ID IS NULL AND m.published_state=1;也就是说,...

php – 如何使用至少每组查询进行左连接?【代码】

我正试图让一个有点复杂的查询工作,并没有任何运气. 假设我有以下表格: cart_items:+--------------------------------------------+ | item_id | cart_id | movie_name | quantity | +--------------------------------------------+ | 0 | 0 | braveheart | 4 | | 1 | 0 | braveheart | 9 | | . | . | . | . | | . | . | . | ...

php – Laravel – 查询构建器 – 左连接多态关系,仅限于distinct【代码】

所以我使用Vue 2.0和Laravel 5.3来创建一个应用程序. 我使用Laravel提供的内置分页,用Vue实现了自己的可排序表. 一切都很完美 – 除了,我正试图加入一个“媒体”多态表,所以我可以在我的表中显示一个图像. 为了启用排序,我不得不使用查询构建器,因为您无法使用Eloquent(AFAIK)对关系进行排序. 我定义我的关系如:$inventories = $inventories->leftjoin('users as inventory_user', 'inventories.user_id', '=', 'inventory_user.i...

php – Codeigniter 2.2 – 使用左连接和多个where子句的Active Record更新【代码】

我有以下SQL:UPDATE msh_leads ml LEFT JOIN msh_leads_disposition_log dl ON ml.id = dl.lead_id SET ml.assigned_to = null WHERE ((dl.disposition_id != 6 AND dl.disposition_id != 3) OR (dl.disposition_id IS NULL)) AND (ml.assigned_to = ? AND ml.decline = 0 AND ml.subcategory_id = ?)创建它有一些逻辑(根据某些情况,某些地方来来去去)所以我希望在Codeigniter(2.2)Active Record中重新创建它.我不知道如何将连接添...

php – 左连接计数忽略左表列从计数【代码】

我有两个表…首先有order_id,order_status和user_id ….第二个表有order_id,product_id,product_quantity如下 第一桌order_id | order_status | user_id----------------------------1 | 5 | 22 | 1 | 13 | 5 | 14 | 5 | 1第二张表order_id | product_id | quantity ---------------------------- 1 | 200 | 4 2 | 201 | 2 ...

PHP-mysql左连接需要太长时间【代码】

我有以下SQL查询:SELECT upd.*,usr.username AS `username`,usr.profile_picture AS `profile_picture` FROM updates AS upd LEFT JOIN subscribers AS sub ON upd.uid=sub.suid LEFT JOIN users AS usr ON upd.uid=usr.uid WHERE upd.deleted='0' && (upd.uid='118697835834' || sub.uid='118697835834') GROUP BY upd.id ORDER BY upd.date DESC LIMIT 0, 15我在其中获取所有用户(118697835834)更新,使用左联接从另一个表获得他...

php – 如果有2个具有相同名称的列,如何选择左连接中的列? [MySQL的]【代码】

我做了一个LEFT JOIN来从我的数据库中获取2个表的值.查询是这样的:SELECT * FROM threadLEFT JOIN comments ON thread.id_thread = comments.id_thread WHERE id_type = '1' ORDER BY data DESC, hour DESC然后我以这种方式输出值:<?while($row = mysqli_fetch_array($query)) { echo '<div class="col-md-1"></div>'; echo '<div class="col-md-11">'; echo $row['title'] ."<br><br>".$row['content']."<br><br>"; echo $row...

php – mysql左连接两个表【代码】

假设我有2个表: leave_typeid name 1 maternity leave 2 Medical leave 3 Casual Leave 4 Sick Leave 5 honeymoon Leaveemployee_leave_blanceid employee_id year leave_type_id val 1 4 2015 1 9 2 4 2015 2 5 3 8 2015 1 10 4 ...

php – 使用Eloquent在mysql中左连接后分别获取相同的命名列【代码】

我有2个表,其中一个存储学生,另一个存储管理员 学生姓名,最终管理者也有名字和姓氏. 我还在学生表中存储了added_by,以检查添加了学生的经理. 随着查询我连接表$students = \App\Student::with('payment')->with('discontinuities')->leftJoin('managers','students.added_by','=','managers.id')->get();让我们说学生是Name Surname Added_by Jon Doe 1和经理是id name surname 1 jane doe所以当我用上面给出的查询加入这两...

php – MYSQL:仅选择最新记录(在左连接表中)【代码】

我有2张桌子:Table1: ID | Mobile Number | Name | Ordered Product| Order Date表2:ID(foreign_key can be inserted multipletimes in this table) |Contacted_for | Time(timestamp)我需要一个查询来显示Table1中的所有数据,如果表2中有ID,我需要显示该ID的Table2(随时间)的最后插入记录 我的疑问是select a.* , b.* FROM table1 a LEFT JOIN table2 b ON a.ID=b.ID GROUP BY a.ID ORDER BY b.Time DESC在我的查询中,当我删除G...