当前位置:网站首页>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()
边栏推荐
- RDB persistence validation test
- Consumer microservice Governance Center stepping on the pit
- 二叉树常见面试题
- June training (the 26th day) - collective search
- Vscode environment setup: synchronous configuration
- Easyexcel - Excel read / write tool
- 搜索引擎高级搜索方法记录
- 最牛X的CMDB系统
- ISO 26262 - 2 functional safety concept
- Global and Chinese market of contemporary lampshade 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

See how I store integer data in the map < string, string > set

ISO 26262之——2功能安全概念

Origin of b+ tree index

OpenCV图像处理-灰度处理

携程机票 App KMM 跨端 KV 存储库 MMKV-Kotlin | 开源

哪些PHP开源作品值得关注

2021 Q3-Q4 Kotlin Multiplatform 使用现状 | 调查报告

AdaptiveAvgPool2D 不支持 onnx 导出,自定义一个类代替 AdaptiveAvgPool2D

栖霞市住建局和消防救援大队开展消防安全培训

Express (I) - easy to get started
随机推荐
JWT certification agreement -- I opened a Yihong hospital
2、 Linear table
[echart] II. User manual and configuration item reading notes
nacos2.x.x启动报错信息Error creating bean with name ‘grpcClusterServer‘;
Plookup table in appliedzkp zkevm (8)
ACK攻击是什么意思?ACK攻击怎么防御?
Is it safe to use flush mobile phones to speculate in stocks? How to fry stocks with flush
Express (I) - easy to get started
Work report (3)
Fabric.js 上划线、中划线(删除线)、下划线
Is it safe for compass software to buy stocks for trading? How to open an account to buy shares
ISO 26262 - 2 functional safety concept
Based on Zeng Shen's explanation, the line segment tree is studied again one
Work report (2)
JWT (SSO scheme) + three ways of identity authentication
Vscode environment setup: synchronous configuration
Redis knowledge mind map
工作汇报(3)
Update mysql5.6 to 5.7 under Windows
MySQL模糊查询详解