简体   繁体   English

如何在Laravel 5 SQL查询中按日期排序?

[英]How to order by date in laravel 5 SQL Query?

I want to select the date value and count the number of it's appearance order by the date. 我想选择日期值并按日期计算其出现顺序的数量。 this is my SQL Query code: 这是我的SQL查询代码:

$b = DB::table('entry')
                        ->select(DB::raw("DATE_FORMAT(created_at,'%d-%m-%Y') as tanggal"))
                        ->groupBy(DB::raw("DATE_FORMAT(created_at,'%d-%m-%Y')"))
                        ->orderBy(DB::raw("CONVERT(DateTime, DATE_FORMAT(created_at,'%d-%m-%Y'), 101)"))
                        ->get();

What's wrong with that query?, help me guys, thanks. 该查询出了什么问题?,帮助我,谢谢。

You seem to have way to many parenthesis of subgroupings. 您似乎可以对子分组进行许多括号处理。 For the last line, get(); 对于最后一行,get(); I don't see how any program would know what value inside parenthesis you are trying to get as there are a total of 9 items within parenthesis in your 3 lines. 我看不到任何程序会如何知道圆括号内的值,因为您的圆括号内的3行中总共有9个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM