LoginSignup
3
3

More than 5 years have passed since last update.

みんなの為のMySQLまとめ(12)

Posted at

参考
http://homepage2.nifty.com/sak/w_sak3/doc/sysbrd/mysql_15.htm

■多重判定

・Oracle と同じように case が使えるので非常に強力である。

select key1,
case
when key1 = 'a001' then 'aaa'
when key1 = 'b002' then 'bbb'
when key1 = 'c003' then 'ccc'
else 'xxx'
end c1
from testm
;
kobito.1424161064.111206.png

select key1,
case key1
when 'a001' then 'aaa'
when 'b002' then 'bbb'
when 'c003' then 'ccc'
else 'xxx'
end c1
from testm
;

■ヌル判定

・coalesce() 関数は、最初の null でないデータを返す。

select coalesce(null, 'abc', 'def');

kobito.1424161225.805742.png

■ヌル比較

・nullif() 関数は、等しければ null が、等しくなければデータ1 が返る。
次の例は、null が返る。

select nullif('abc', 'abc');

kobito.1424161336.760713.png

・次の例は、'abc' が返る。

select nullif('abc', 'def') ;

kobito.1424161369.223115.png

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3