MySQL的IFNULL ELSE [英] mysql IFNULL ELSE

查看:843
本文介绍了MySQL的IFNULL ELSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条select语句,我想在其中选择条件,

I have a select statement where I want to make select conditional like this

IFNULL(field_a,field_a,feild_b)

以便它检查字段a如果a为空,则选择字段为b

so that it checks field a if a is null then the select would be field b

那有可能吗?

推荐答案

使用凉粉:

SELECT COALESCE(field_a, field_b)

COALESCE是ANSI标准函数,它从指定的列列表中返回第一个非空值,并从左到右处理这些列.因此,在示例中,如果field_a为null,则将显示field_b值.但是,如果指定的列中没有非空值,则此函数将返回NULL.

COALESCE is an ANSI standard function that returns the first non-null value from the list of columns specified, processing the columns from left to right. So in the example, if field_a is null, field_b value will be displayed. However, this function will return NULL if there is no non-null value from the columns specified.

它在MySQL(我在4.1上使用过),SQL Server(从v2000开始),Oracle 9i +上受支持.

It's supported on MySQL (I've used it on 4.1), SQL Server (since v2000), Oracle 9i+...

这篇关于MySQL的IFNULL ELSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆