Skip to content

Transforming SQL into QueryBuilder #8853

@bglevon

Description

@bglevon

Hello,

I have an SQL query that I need to do in QueryBuilder, but I can't get it because of multiple leftJoin.

Here is my SQL query

SELECT r.lot,DATE_FORMAT(r.datetime_creation,'%d-%m-%Y %H:%i') as date_creation, u.societe, j_3.date_cloture , COUNT(r.id_reparation) as nb_element, j_2.nb_element_total
, IF(j_1.nb_element_cloture IS NULL,0,CONVERT((j_1.nb_element_cloture * 100 / j_2.nb_element_total),int)) as progression
FROM utilisateur u, reparation r
LEFT JOIN (SELECT COUNT(*) as nb_element_cloture, lot FROM reparation WHERE fk_reparation_statut_id IN (5,10,11,14,15,23,24,27)  GROUP BY lot) j_1 ON j_1.lot = r.lot
LEFT JOIN (SELECT COUNT(*) as nb_element_total, lot FROM reparation WHERE fk_reparation_statut_id > 0 GROUP BY lot) j_2 ON j_2.lot = r.lot
LEFT JOIN (SELECT DATE_FOreparationT(datetime_cloture ,'%d-%m-%Y %H:%i') as date_cloture,lot
              FROM reparation
              WHERE fk_reparation_statut_id IN (5,10,11,14,15,23,24,27)
              GROUP BY lot
             ORDER BY datetime_cloture DESC) j_3 ON j_3.lot = r.lot
  WHERE r.fk_reparation_statut_id IN(1, 16)
    AND r.revendeur = u.id_utilisateur

Is it possible to put the SELECT in the leftJoin with QueryBuilder? and if so how should I proceed?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions