Sunday, January 16, 2022

[FIXED] DoctrineSelect with Variable

Issue

I'm trying something like this with doctrine:

SELECT 
    @myprice := cp.price,
    @compPrice1 := (SELECT cpt1.price FROM competitor_product AS cpt1 
                    WHERE cpt1.product_id = cp.product) as compPrice1 
    @compPrice1 / @myprice  AS price_diff
FROM
    customer_product AS cp 
WHERE 
    customer_id = 1;

My code until then:

[my code until then]1

How can I set variable for use in calculate column?

I've been looking for but found nothing about


Solution

I don't think this is possible with Doctrine Query builder. I would suggest use Doctrine Native Query or Raw SQL queries.



Answered By - Mohamed Sharfaz Sairaz

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.