当前位置:网站首页>laravel中使用group by分组并查询数量
laravel中使用group by分组并查询数量
2022-06-26 10:04:00 【siner.li】
实例
$num = DB::table('addr_number')
->select('address', DB::raw('count(*) as num'))
->groupBy('address')->get();
dd($num);
打印
Illuminate\Support\Collection {#1578 ▼
#items: array:2 [▼
0 => {#1583 ▼
+"address": "南天门"
+"num": 1
}
1 => {#1576 ▼
+"address": "东海"
+"num": 2
}
]
}
实例说明
// 其中的字段是我们所需要返回的字段
->select('address', DB::raw('count(*) as num'))
// 按其中的字段进行分组
->groupBy('address')->get()
边栏推荐
- 看我在Map<String, String>集合中,存入Integer类型数据
- 【软件项目管理】期末复习知识点整理
- Oracle11g 启动数据库时报错 ORA-27154: post/wait create failed
- JS take the date of the previous month 【 pit filling 】
- appliedzkp zkevm(8)中的Plookup Table
- Easyx-----c语言实现2048
- Work report (3)
- Enter a positive integer with no more than 5 digits, and output the last digit in reverse order
- Easyexcel - Excel read / write tool
- 在Oracle中update大量数据会不会导致undo空间爆掉
猜你喜欢

Flutter与原生通信(上)

02-Redis数据结构之链表

SVN 安装配置

SSH, SCP command appears permission denied, please try again solution

Vscode environment setup: synchronous configuration

Redis (basic) - learning notes

DataBinding使用与原理分析

Flutter and native communication (Part 1)

Function run time

MySQL 12th job - Application of stored procedure
随机推荐
Fabric. JS upper dash, middle dash (strikethrough), underline
哪些PHP开源作品值得关注
Global and Chinese market for change and configuration management software 2022-2028: Research Report on technology, participants, trends, market size and share
Server single and two-way adjustable one key mutual trust script!
量化投资学习——经典书籍介绍
【深度学习理论】(7) 长短时记忆网络 LSTM
Work report (3)
搜索引擎高级搜索方法记录
JWT certification agreement -- I opened a Yihong hospital
Sqli-labs靶场1-5
代码规范 & 详细解释 husky、prettier、eslint、lint-staged 的作用和使用
SSH, SCP command appears permission denied, please try again solution
JWT (SSO scheme) + three ways of identity authentication
Hazelnut cloud - SMS (tool)
ISO 26262 - 2 functional safety concept
小笔记-简单但够用系列_KVM快速入门
c语言 --- 运算符和表达式
Developers, what is the microservice architecture?
Idea remote debugger
Redis (basic) - learning notes