当前位置:网站首页>Super sub query implements join query gracefully
Super sub query implements join query gracefully
2022-07-17 23:27:00 【tiwayDeng】
demand

The above activity list needs to be associated with the activity classification table , Commodity table and query conditions accordingly . How to gracefully implement queries with relatively good performance for different conditions
For example, we should vaguely search the activity name from the activity table 、 Search the product name vaguely from the product list 、 Filter according to activity classification
Code
We are service Layer implementation
public function getList(array $params)
{
// Activity subquery
$actSub = $this->actRepo->where('store_id', $this->storeId);
// Commodity sub query
$goodsSub = $this->goodsRepo->select(['goods_id', 'goods_name']);
// The name of the event
if (!empty($params['title'] ?? '')) {
$actSub->where('title', 'like', '%' . $params['title'] . '%');
}
// Name of commodity
if (!empty($params['goods_name'] ?? '')) {
$goodsSub->where('goods_name', 'like', '%' . $params['goods_name'] . '%');
}
// classification
if (!empty($params['cate_id'] ?? '')) {
$actSub->where('cate_id', $params['cate_id']);
}
// state
if (isset($params['status'])) {
$actSub ->where('status', $params['status']);
}
//join Associate two subqueries
$query = $this->actRepo->select('activity.*', 'goods.goods_name')
->fromSub($actSub, 'activity');
$query->joinSub($goodsSub, 'goods', function ($join) {
$join->on('activity.goods_id', '=', 'goods.goods_id');
});
// In reverse order
$query->orderBy('activity.id', 'desc');
$acts = PaginationHelper::appLists($query);
return $acts;
}
Our idea is to add sub queries , Each table creates a subquery , This performance is better , And it can insert the corresponding condition query gracefully
Summary
Of course, implementing this list is a piece of cake for everyone , Maybe you already know this way of writing , I'm kidding ~, I have also written this kind of list natively , But I haven't thought about it before using the framework's own sub query
边栏推荐
- C语言中的关键字struct、union、enum、typedef
- 淘宝官方商品、交易、订单、物流接口列表(淘宝oAuth2.0接口)
- 扎心了!39岁买房后就被裁员了
- Proxmox ve 7.2 creating standard virtual machines
- Go语言指针
- 企业命名规范
- Hcip seventh day notes
- Is it safe to buy funds in a stock account. Can you make a short line
- Hra2460d-2w high voltage power chip IC power supply
- Kotlin 点击空白位置隐藏软键盘
猜你喜欢

vs2019社區版下載教程(詳細)

C语言之数组参数,指针参数,函数指针,函数指针数组

The problem of idea configuring NPM to jump to 0.0.0.0 after startup is solved

15.1.2、MySQL—mysql时间与时间戳转换的函数,unix_timestamp、from_unixtime

浅解volatile

字符串函数的介绍及模拟实现

Proxmox ve 7.2 importing virtual machines from CT templates

Software test interface test interface authentication token authentication mock server interface encryption and decryption interface signature

Practice and application of Flink flow processing in CSC securities

Session tracking technology cookies and sessions
随机推荐
Software test interface test interface authentication token authentication mock server interface encryption and decryption interface signature
京东店铺所有商品API接口(JD整店商品查询API接口)
nVisual API接口使用说明
R language basic function assign function
hyper子查询优雅实现join查询
Taobao app product details API interface (product details description information query interface)
微信小程序相关知识点和云音乐项目制作遇到的问题及解决
My heart's broken! After buying a house at the age of 39, he was laid off
Bool type and related operators
Kotlin 点击空白位置隐藏软键盘
Implementation of wechat applet Netease cloud music cloud music
Week 4 Data analysis algorithms-Linear models for regression-Bias-Variance Analysis(Part B)
微信公众号-服务器配置(token验证)
15.1.1、MySQL—mysql的日期时间函数,日期格式化
微信公众号开发-自定义菜单
[security dog] Microsoft updated and solved multiple vulnerabilities in July
HCIP第七天笔记
Proxmox ve 6 updated to 7
【安全狗】微软7月多个漏洞更新解决
Hcip seventh day notes