当前位置:网站首页>Laravel 实现 groupBy 查询分组数量
Laravel 实现 groupBy 查询分组数量
2022-06-26 06:07:00 【兄弟你的假发】
如何用laravel来实现以下sql呢?
select `book_name`, count(*) as num from `clock_books` group by `book_name`
可使用laravel的原始表达式DB::raw()来操作:
$books = DB::table('books')
->select('book_name', DB::raw('count(*) as num'))
->groupBy('book_name')
->get();
||
$users = DB::table('books')
->select(DB::raw('count(*) as num, book_name'))
->groupBy('book_name')
->get();
边栏推荐
猜你喜欢

The interviewer with ByteDance threw me an interview question and said that if I could answer it, other companies would have an 80% chance of passing the technical level

Design and practice of low code real-time data warehouse construction system

Detailed explanation of serial port communication principle 232, 422, 485

100 cases of go language

Pychart cannot run designer Exe (this application failed to start because no Qt platform plugin could be I appears)

Install pyinstaller

Logstash - logstash pushes data to redis

事务与消息语义

Architecture design method

技术能力的思考和总结
随机推荐
GoF23—建造者模式
Architecture design method
事务与消息语义
Message queue - function, performance, operation and maintenance comparison
技术Leader的思考技巧
Tortoise and rabbit race example
Factory method pattern, abstract factory pattern
GoF23—抽象工厂模式
Several promotion routines of data governance
Machine learning 07: Interpretation of PCA and its sklearn source code
Prototype mode, Baa Baa
Cython入门
低代码实时数仓构建系统的设计与实践
Ppt template crawler case
Matching environment of ES6
Level signal and differential signal
Implement the runnable interface
05. basic data type - Dict
Basic construction of SSM framework
On site commissioning - final method of kb4474419 for win7 x64 installation and vs2017 flash back