我需要数小时。这是我的laravel雄辩:
$items = Item::ofType('type')->where('start_at','>=',Carbon::today())->groupBy(\DB::raw('HOUR(start_at)'))->count();
这显示了我的结果,如2/2/1
sql查询:
SELECT
count(*)AS AGGREGATE
FROM
`items`
WHERE
`type` = 'type'
AND `start_at` >= '2015-10-15 00:00:00'
GROUP BY
HOUR(start_at)
如何计算2/2/1,得到结果= 3?
我需要没有RAW的laravel雄辩。
编辑:
SELECT COUNT(*) FROM (SELECT
count(*) AS AGGREGATE
FROM
`items`
WHERE
`type` = 'type'
AND `start_at` >= '2015-10-15 00:00:00'
GROUP BY
HOUR(start_at)) as count
如何用laravel eloquent写这个?
答案 0 :(得分:0)
您可以在此链接上使用此代码检查laravel文档。 http://laravel.com/docs/4.2/queries
按顺序,分组依据和
$users = DB::table('items')
->orderBy('name', 'desc')
->groupBy('count')
->having('count', '>', 100)
->get();