mysql之coalesce:
在 MySQL 8 中,COALESCE 函数用于返回表达式列表中第一个非 NULL 的值。如果所有表达式都是 NULL,那么 COALESCE 返回 NULL。它通常用于在查询中处理可能包含 NULL 值的列。
使用:
COALESCE(expression1, expression2, ..., expressionN)
expression1, expression2, ..., expressionN 是要检查的表达式。
它会从左到右依次检查,返回第一个非 NULL 的表达式值。
如果所有表达式都是 NULL,则返回 NULL
例子:
SELECT user_id,
COALESCE(address1, address2, address3, 'No Address') AS primary_address
FROM users;
有时候可以和IFNULL起到相同的作用.
https://dev.mysql.com/doc/refman/8.4/en/comparison-operators.html#function_coalesce
mysql之concat-ws:
这个方法默认的doctrine不支持,在symfony框架下使用需要安装: composer require beberlei/doctrineextensions 拓展, 同时需要配置,参考: https://symfony.com/doc/current/doctrine/custom_dql_functions.html
https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_concat-ws
