简体   繁体   中英

Using something similar to a CASE WHEN in Phalcon query builder

$fileQueryBuilder->columns(
            [
                "id" => "d.discovered_file_id",
                "company_name" => "d.company_name"
            ]
        );

This is the part of my query builder where I mention the column names to be selected/displayed. Can I handle the 'company_name' field to show it's value if it has one, and something like 'Not available' if it's empty, in this part of the query builder itself? Is there a way of doing that, like using a CASE WHEN same as in SQL?

What I tried-
CASE WHEN d.company_name IS NOT NULL THEN d.company_name ELSE 'Not available' END => d.company_name , but this doesn't work.

Isn't IF better in this case?

IF(d.company_name IS NOT NULL, d.company_name, 'Not available') as company_name

Also PHQL only supports case syntac like this:

CASE column WHEN value THEN some expression ELSE some expression END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM