0
I run a consultation on MySQL
that works and on Laravel
no, following
SQL:
select resource_id as "pedido", count(resource_id) as "perguntas",
date_received from perguntas_pos where status="UNANSWERED"
group by 1 order by 2 desc
and when I spin in the Laravel
says the following error:
SQLSTATE[42000]: Syntax error or access violation: 1055 'pergunta_ml.perguntas_pos.date_received' isn't in GROUP BY (SQL: select resource_id as "pedido", count(resource_id) as "perguntas", date_received from perguntas_pos where status="UNANSWERED" group by 1 order by 2 desc)
Why do I have to put the date_received
in the GROUP BY
also?
I think one of the problems is the use of quotation marks on:
...as "pedido"
and...as "perguntas"
. Try first to remove these quotes.– user98628
Paul, I made the change and it’s not the quotes.
– milho
To use the
GROUP BY
, you must specify columns and not numbers. Check this link: https://www.w3schools.com/sql/sql_groupby.asp– user98628
You can show your code in the program you are running as well?
– guastallaigor
Put the code you made on Laravel!
– novic
class Pedidoscontroller extends Controller { public Function requests() { $orders = DB::select('select resource_id, Count(resource_id) questions, date_received from questions_pos Where status="UNANSWERED" group by 1 order by 2 desc'); Return view('orders.orders')-> with('orders', $orders); }
– milho