laravel 4.2中的子查询

时间:2015-07-23 10:58:51

标签: php mysql laravel eloquent

我有以下mysql查询在laravel中运行,但我无法弄清楚应该如何实现它。

这是MYSQL查询。

SELECT temp.*,count(temp.respondent_id) FROM (SELECT * FROM `responses` GROUP BY respondent_id) as temp GROUP BY DAY(`temp`.`created_at`)

我得到了预期的结果。请帮帮我。 提前感谢你。

2 个答案:

答案 0 :(得分:1)

嘿,我有解决方案。

作为stachu 给出链接" Solution 1"在评论中。

&安培;另一种方式如下

$data = \DB::select(\DB::raw('SELECT count(temp.respondent_id) as respondent, DATE(temp.created_at) as date FROM (SELECT * FROM `responses` GROUP BY respondent_id) as temp GROUP BY DAY(`temp`.`created_at`)'));

希望得到这个帮助。

答案 1 :(得分:0)

试试这个,

 $result = DB::select("SELECT temp.*,count(temp.respondent_id) FROM (SELECT * FROM `responses` GROUP BY respondent_id) as temp GROUP BY DAY(`temp`.`created_at`)");