如果已选择的另一列为空,则选择一列

时间:2012-11-03 05:54:01

标签: mysql

DEV|MUL
xyz|null
null|abc
123|456

我想获取另一个为null的列的值,或者如果两者都具有来自mysql的值,则获取一列专用

3 个答案:

答案 0 :(得分:1)

您可以使用IFNULL

SELECT IFNULL(DEV, MUL) as Col FROM myTable  -- MySql

SELECT ISNULL(DEV, MUL) as Col FROM myTable  -- SQL Server

SELECT NVL(DEV, MUL) as Col FROM myTable  -- Oracle

答案 1 :(得分:0)

SELECT IFNULL(DEV, MUL) AS VALUE from table table1; 

如果DEVnot null,则返回MUL列值,否则返回{{1}}列值。

答案 2 :(得分:0)

select * from tablename where (columnname is null)
and
select * from tablename where (columnname1 is null) and (columnname2 is null)