Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maltekiefer's avatar

SQL to Elequent with from sub query

Hello,

is there a way, to get from this SQL:

SELECT *,

  (SELECT count(*)
   FROM addresssurveys
   WHERE savedtimestamp::date = sendout_date) AS y
FROM
  (SELECT created_at::date AS sendout_date,
          created_at::date AS x
   FROM addresssurveys
   GROUP BY created_at::date) AS main

an Eloquent statement? I created already the sub from query:

 $sub = Survey::select(DB::raw('created_at::date, created_at::date as sendout_date, created_at::date as x'))->groupBy(DB::raw('created_at::date'))->orderby('created_at')->get();

But how can I combine both?

Thanks

0 likes
1 reply
bobbybouwmann's avatar

This is a very specific query. I would probably just do a full raw query here.

1 like

Please or to participate in this conversation.