6.5: MySQL
, - . , .
IFNULL(expr1, r2)
expr1 NULL, IFNULL () expr1, expr2. IFNULL() , :
mysql> select IFNULL(1,0);
-> 1
mysql> select IFNULL(NULL,10);
->10
mysql> select IFNULL(1/0,10);
->10
mysql> select IFNULL(1/0,'yes');
-> "yes"
NULLIF(expr1, expr2)
expr1=expr2, NULL, expr1. -, CASE WHEN = THEN NULL ELSE x END ( ):
mysql> select NULLIF(1,1);
-> NULL
mysql> select NULLIF(1,2);
-> 1
, expr1 MySQL, .
IF(expr1, expr2, r)
expr1 TRUE (expr1 <> 0 exprl <> NULL), IF() r2, r. IF() , :
mysql> select IF(1>2,2,3);
-> 3
mysql> select IF(1<2,'yes','no');
-> yea"
mysql> select IF(strcmp("test",'test1'),'no','yes');
-> "no"
expr1 . , , , :
mysql> select IF(0.1,1,0);
-> 0
mysql> select IF(0.1<>0,1,0);
-> 1
IF (0.1) 0 , 0.1 , IF (0). , , . . IF () ( , ) MySQL 3.23 (. 6.1):
6.1. IF()
r2 r | |
r2 r | |
r2 r | |
r2 r |
CASE value WHEN [compare-value] THEN result [WHEN [compare-value] THEN result ...] [ELSE result] END CASE WHEN [condition] THEN result [WHEN [condition] THEN result ...] [ELSE result] END.
. , , . .
result, value = compare - value. , . , , ELSE. ELSE, NULL:
mysql> SELECT CASE 1 WHEN 1 THEN one WHEN 2 THEN two ELSE more END;
-> one
mysql> SELECT CASE WHEN 1>0 THEN true ELSE false END;
-> true
mysql> SELECT CASE BINARY » when then 1 when b then 2 END;
-> NULL
(INTEGER, DOUBLE STRING) , ( THEN).