没有 where 条件 – 永夜 https://www.shuijingwanwq.com 没有不值得去解决的问题,也没有不值得去学习的技术! Thu, 23 May 2024 01:48:56 +0000 zh-Hans hourly 1 https://wordpress.org/?v=7.0 在 Laravel 查询生成器中检查表是否已经有 where 条件的实现 https://www.shuijingwanwq.com/2024/05/23/8596/ https://www.shuijingwanwq.com/2024/05/23/8596/#respond Thu, 23 May 2024 01:48:56 +0000 https://www.shuijingwanwq.com/?p=8596 浏览量: 62 1、参考:在 MySQL 8.0 中,查询表记录总数时,超时的分析优化。当一条 count SQL 没有 where 条件存在时,就添加 WHERE id > 0。 2、参考:How to check if table is already has a where clause in Laravel Query Builder?  最终实现如下


	if (empty($builder->getQuery()->wheres)) {
		$builder->where('id', '>', 0);
	}


3、最终生成 SQL 如下,符合预期


select count(*) as aggregate from `tables` where `id` > 0


   ]]>
https://www.shuijingwanwq.com/2024/05/23/8596/feed/ 0