vendredi 22 décembre 2017

Need help in optimising Laravel Mysql query

Can anyone help me out in explaining this below query in detail? This is part of my project which i got to debug. i need help to understand it and optimise this.

$query = seller::selectRaw("seller.name, seller.group_id,seller.group_id_string, seller.pay,( 
    SELECT SUM( IF( t.retail_cost >0
    AND t.submitted_group_plan >1, 1 , -1 ) ) AS trans_number
    FROM money AS t
    JOIN  `seller` AS d ON  `t`.`submitted_group_plan` =  `d`.`group_id` 
    WHERE 
    (
        (
        t.`claim_date_and_time` >=  '01-01-2015'
        AND t.`claim_date_and_time` <=  '01-01-2016'
        AND t.commissionable =  'Y'
        AND t.`submitted_group_plan` = d.group_id
        )
        OR 
        (
            (t.commissionable IS NULL)
            AND 
            (t.claim_type_code IS NULL)
            AND
            (t.claim_date_and_time IS NULL)
        )
    )
    AND d.id = seller.id)
    as trans_number");  

MYSQL VERSION OF ABOVE QUERY:

SELECT seller.name,
       seller.group_id,
       seller.group_id_string,
       seller.pay,

  (SELECT SUM(IF(t.retail_cost >0
                 AND t.submitted_group_plan >1, 1, -1)) AS trans_number
   FROM money AS t
   JOIN `seller` AS d ON `t`.`submitted_group_plan` = `d`.`group_id`
   WHERE ((t.`claim_date_and_time` >= '01-01-2015'
           AND t.`claim_date_and_time` <= '01-01-2016'
           AND t.commissionable = 'Y'
           AND t.`submitted_group_plan` = d.group_id)
          OR ((t.commissionable IS NULL)
              AND (t.claim_type_code IS NULL)
              AND (t.claim_date_and_time IS NULL)))
     AND d.id = seller.id) AS trans_number
FROM `seller`



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire