Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

660
Views
Generador de consultas GROUP BY, HAVING, COUNT en Laravel

cómo expresar este código en el generador de consultas. Estoy usando Laravel 6.

 SELECT * FROM feedback GROUP BY noTicket having count(`status`) < 2

Mi código:

 $feedback = DB::table('feedback') ->groupBy('noTicket') ->having('count(status)', '<', 2) ->get();

Código de error:

 SQLSTATE[42000]: Syntax error or access violation: 1055 'sifora.feedback.idFeedback' isn't in GROUP BY (SQL: select * from `feedback` group by `noTicket` having `count(status)` < 2)

¿Qué está mal con mi código? Parece una coincidencia entre el código sql y el generador de consultas.

Gracias

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Esta es la versión de trabajo de la consulta.

 select noTicket from feedback group by noTicket having count(status) < 2;

Este es el generador de consultas;

 return DB::table('feedback') ->groupBy('noTicket') ->having(DB::raw('count(status)'), '<', 2) ->pluck('noTicket'); // you may replace this with get()/select()
over 4 years ago · Santiago Trujillo Report

0

Aquí el código completo. Muchas gracias a Ersoy

 $getArray = DB::table('feedback') ->groupBy('noTicket') ->having(DB::raw('count(status)'), '<', 2) ->pluck('noTicket'); $feedback = DB::table('feedback') ->whereIn('noTicket', $getArray)->get();
over 4 years ago · Santiago Trujillo Report

0

$feedback = DB::table('feedback') ->selectRaw('feedback.*, count(status) as count_status') ->groupBy('noTicket') ->havingRaw('count(status) > ?', [2]) ->get();

También existe un modo estricto, puede deshabilitarlo en config/database.php

 'connections' => [ 'mysql' => [ 'strict' => false ] ]

Pero no te recomiendo que lo hagas. Consulte esto https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html aquí obtendrá más información sobre cómo funciona el grupo.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!