1

I have below mysql query to run in laravel but i am not able to figure out how should i implement it.

Here is MYSQL query.

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

I am getting expected result with it. Please help me out. Thanking you in advance.

Vishal Tarkar
  • 808
  • 11
  • 32
  • http://stackoverflow.com/questions/16815551/how-to-do-this-in-laravel-subquery-where-in something like that? – ventaquil Jul 23 '15 at 11:07
  • No, I have read this link. But here my table coming from query which is same table. – Vishal Tarkar Jul 23 '15 at 11:09
  • So maybe something like that: http://stackoverflow.com/questions/24823915/how-to-select-from-subquery-using-laravel-query-builder – ventaquil Jul 23 '15 at 11:11
  • 1
    Yes. It can be work. But i just have implemented this solution. "" $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`)')); "" AND yes it is working. :) – Vishal Tarkar Jul 23 '15 at 11:18
  • I am happy that I could help you :) – ventaquil Jul 23 '15 at 11:18

2 Answers2

1

Hey I have got solutions.

As stachu given link "Solution 1" in comments.

& another way is as below

$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`)'));

Hope this help.

Community
  • 1
  • 1
Vishal Tarkar
  • 808
  • 11
  • 32
0

Try this,

 $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`)");
alagu
  • 779
  • 1
  • 5
  • 19