Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在日期上应用 groupBy 查询(按年份)问题是我只有一列日期,它存储像这样的日期 2010-11-01 我想只做一年的组
看起来您的数据库已正确设计为将日期列作为日期类型。您应该按YEAR()日期值的值分组。
YEAR()
调用该groupBy()方法并传入原始 sql YEAR(your_date_column_name)。
groupBy()
YEAR(your_date_column_name)
->groupBy(DB::raw('YEAR(your_date_column_name)')