Expected known function,got 'IF'
使用IF执行此查询时:
$qb->select("c.id,IF(c.type_id LIKE 9,c.name,c.lastname) as name")
最佳答案
是的,如果不支持原则中的陈述,您可以将其转换为大小写
IF(c.type_id LIKE 9,c.lastname) as name
至
case when c.type_id = 9 then c.name else c.lastname end as name
更新:
从注释中,在case-when中允许使用concat函数
非常允许答案是肯定的.这是一个例子
MysqL> select * from timesheets ;
+-----------+-------+----------+
| client_id | hours | category |
+-----------+-------+----------+
| 1 | 1.50 | onsite |
| 1 | 1.50 | onsite |
| 1 | 1.00 | remote |
| 2 | 1.50 | remote |
+-----------+-------+----------+
4 rows in set (0.00 sec)
MysqL> select
case when category = 'onsite' then concat('ON',' ',hours) else hours
end as dd from timesheets ;
+---------+
| dd |
+---------+
| ON 1.50 |
| ON 1.50 |
| 1.00 |
| 1.50 |
+---------+
4 rows in set (0.00 sec)