How to add Where condition on Virtual column in Typeorm

572 Views Asked by At

Can someone help me in below query I always get x.salesChannel as Unknown column

SELECT Column1,
    Column2,
    (
        SELECT CASE
                WHEN `cr`.`CRColumn` is not null
                AND `cr`.`CRColumn` <= `ca`.`caColumn` THEN `cr`.`CRColumn`
                WHEN `cr`.`CRColumn` is not null
                AND `cr`.`CRColumn` > `ca`.`caColumn` THEN `cr`.`CRColumn`
                WHEN `cr`.`CRColumn` is not null
                AND `cr`.`CRColumn` is null THEN `cr`.`CRColumn`
            END as salesChannel
        FROM `table1` `ca`
            LEFT JOIN `Table2` `bc` ON `bc`.`contract_action_id` = `contract`.`id`
            LEFT JOIN `Table3` `cr` ON `cr`.`pnr` = `bc`.`pnr`
    ) AS `x`
FROM `table1` `contract`
WHERE `contract`.`type` = ?
    AND x.salesChannel IS NOT NULL
    AND x.salesChannel IN (?, ?)
0

There are 0 best solutions below