In mysql, there are actually many methods and functions that are very useful. This time I introduce one called coalesce. It is very troublesome to spell, but its function is to pass the returned The first non-null value in the entered parameter. The following article mainly introduces relevant information on the usage techniques of coalesce() in mysql. Friends in need can refer to it.
Preface
Recently I accidentally discovered coalesce of mysql, and I just had time, so I added mysqlcoalesce()## The usage skills of # are summarized and shared with everyone. Let’s take a look at the detailed introduction:
coalesce() explanation
In the return parameters The first non-emptyexpression (and so on from left to right);
Threevariablesa,b,c.
select coalesce(null,2,3); // Return 2 select coalesce(null,null,3); // Return 3 select coalesce(1,2,3); // Return 1
SELECT COALESCE(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1); -- Return 1
SELECT COALESCE(NULL, NULL, NULL, NULL); -- Return NULL
SELECT COALESCE(字段名,0) as value from t;//(如果数据库提成字段默认值不是为0值的话肯定是开发那个的错,个人观点请勿喷哈)。
Summary
The above is the detailed content of Summary of techniques for using coalesce() in mysql (must read). For more information, please follow other related articles on the PHP Chinese website!