1 drop table if exists t1;
2 select IF(0,"ERROR","this"),IF(1,"is","ERROR"),IF(NULL,"ERROR","a"),IF(1,2,3)|0,IF(1,2.0,3.0)+0 ;
3 IF(0,"ERROR","this") IF(1,"is","ERROR") IF(NULL,"ERROR","a") IF(1,2,3)|0 IF(1,2.0,3.0)+0
5 CREATE TABLE t1 (st varchar(255) NOT NULL, u int(11) NOT NULL) ENGINE=MyISAM;
6 INSERT INTO t1 VALUES ('a',1),('A',1),('aa',1),('AA',1),('a',1),('aaa',0),('BBB',0);
7 select if(1,st,st) s from t1 order by s;
16 select if(u=1,st,st) s from t1 order by s;
25 select if(u=1,binary st,st) s from t1 order by s;
34 select if(u=1,st,binary st) s from t1 where st like "%a%" order by s;
42 explain extended select if(u=1,st,binary st) s from t1 where st like "%a%" order by s;
43 id select_type table type possible_keys key key_len ref rows filtered Extra
44 1 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using where; Using filesort
46 Note 1003 select if((`test`.`t1`.`u` = 1),`test`.`t1`.`st`,cast(`test`.`t1`.`st` as char charset binary)) AS `s` from `test`.`t1` where (`test`.`t1`.`st` like '%a%') order by if((`test`.`t1`.`u` = 1),`test`.`t1`.`st`,cast(`test`.`t1`.`st` as char charset binary))
47 select nullif(u, 1) from t1;
56 explain extended select nullif(u, 1) from t1;
57 id select_type table type possible_keys key key_len ref rows filtered Extra
58 1 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00
60 Note 1003 select nullif(`test`.`t1`.`u`,1) AS `nullif(u, 1)` from `test`.`t1`
62 select nullif(1,'test');
66 Warning 1292 Truncated incorrect DOUBLE value: 'test'
67 select NULLIF(NULL,NULL), NULLIF(NULL,1), NULLIF(NULL,1.0), NULLIF(NULL,"test");
68 NULLIF(NULL,NULL) NULLIF(NULL,1) NULLIF(NULL,1.0) NULLIF(NULL,"test")
70 select NULLIF(1,NULL), NULLIF(1.0, NULL), NULLIF("test", NULL);
71 NULLIF(1,NULL) NULLIF(1.0, NULL) NULLIF("test", NULL)
73 create table t1 (num double(12,2));
74 insert into t1 values (144.54);
75 select sum(if(num is null,0.00,num)) from t1;
76 sum(if(num is null,0.00,num))
79 create table t1 (x int, y int);
80 insert into t1 values (0,6),(10,16),(20,26),(30,10),(40,46),(50,56);
81 select min(if(y -x > 5,y,NULL)), max(if(y - x > 5,y,NULL)) from t1;
82 min(if(y -x > 5,y,NULL)) max(if(y - x > 5,y,NULL))
85 create table t1 (a int);
86 insert t1 values (1),(2);
87 select if(1>2,a,avg(a)) from t1;
91 SELECT NULLIF(5,5) IS NULL, NULLIF(5,5) IS NOT NULL;
92 NULLIF(5,5) IS NULL NULLIF(5,5) IS NOT NULL
95 `id` int(11) NOT NULL ,
96 `date` int(10) default NULL,
97 `text` varchar(32) NOT NULL
99 INSERT INTO t1 VALUES (1,1110000000,'Day 1'),(2,1111000000,'Day 2'),(3,1112000000,'Day 3');
100 SELECT id, IF(date IS NULL, '-', FROM_UNIXTIME(date, '%d-%m-%Y')) AS date_ord, text FROM t1 ORDER BY date_ord ASC;
105 SELECT id, IF(date IS NULL, '-', FROM_UNIXTIME(date, '%d-%m-%Y')) AS date_ord, text FROM t1 ORDER BY date_ord DESC;
111 CREATE TABLE t1 (a CHAR(10));
112 INSERT INTO t1 VALUES ('aaa'), (NULL), (''), ('bbb');
113 SELECT a, NULLIF(a,'') FROM t1;
119 SELECT a, NULLIF(a,'') FROM t1 WHERE NULLIF(a,'') IS NULL;
124 create table t1 (f1 int, f2 int);
125 insert into t1 values(1,1),(0,0);
126 select f1, f2, if(f1, 40.0, 5.00) from t1 group by f1 order by f2;
127 f1 f2 if(f1, 40.0, 5.00)
131 select if(0, 18446744073709551610, 18446744073709551610);
132 if(0, 18446744073709551610, 18446744073709551610)
134 CREATE TABLE t1(a DECIMAL(10,3));
136 IF((ROUND(t1.a,2)=1), 2,
137 IF((ROUND(t1.a,2)=1), 2,
138 IF((ROUND(t1.a,2)=1), 2,
139 IF((ROUND(t1.a,2)=1), 2,
140 IF((ROUND(t1.a,2)=1), 2,
141 IF((ROUND(t1.a,2)=1), 2,
142 IF((ROUND(t1.a,2)=1), 2,
143 IF((ROUND(t1.a,2)=1), 2,
144 IF((ROUND(t1.a,2)=1), 2,
145 IF((ROUND(t1.a,2)=1), 2,
146 IF((ROUND(t1.a,2)=1), 2,
147 IF((ROUND(t1.a,2)=1), 2,
148 IF((ROUND(t1.a,2)=1), 2,
149 IF((ROUND(t1.a,2)=1), 2,
150 IF((ROUND(t1.a,2)=1), 2,
151 IF((ROUND(t1.a,2)=1), 2,
152 IF((ROUND(t1.a,2)=1), 2,
153 IF((ROUND(t1.a,2)=1), 2,
154 IF((ROUND(t1.a,2)=1), 2,
155 IF((ROUND(t1.a,2)=1), 2,
156 IF((ROUND(t1.a,2)=1), 2,
157 IF((ROUND(t1.a,2)=1), 2,
158 IF((ROUND(t1.a,2)=1), 2,
159 IF((ROUND(t1.a,2)=1), 2,
160 IF((ROUND(t1.a,2)=1), 2,
161 IF((ROUND(t1.a,2)=1), 2,
162 IF((ROUND(t1.a,2)=1), 2,
163 IF((ROUND(t1.a,2)=1), 2,
164 IF((ROUND(t1.a,2)=1), 2,
165 IF((ROUND(t1.a,2)=1), 2,0)))))))))))))))))))))))))))))) + 1
167 a IF((ROUND(t1.a,2)=1), 2,
168 IF((ROUND(t1.a,2)=1), 2,
169 IF((ROUND(t1.a,2)=1), 2,
170 IF((ROUND(t1.a,2)=1), 2,
171 IF((ROUND(t1.a,2)=1), 2,
172 IF((ROUND(t1.a,2)=1), 2,
173 IF((ROUND(t1.a,2)=1), 2,
174 IF((ROUND(t1.a,2)=1), 2,
175 IF((ROUND(t1.a,2)=1), 2,
176 IF((ROUND(t1.a,2)=1), 2,
179 CREATE TABLE t1 (c LONGTEXT);
180 INSERT INTO t1 VALUES(1), (2), (3), (4), ('12345678901234567890');
181 SELECT * FROM (SELECT MAX(IF(1, CAST(c AS UNSIGNED), 0)) FROM t1) AS te;
182 MAX(IF(1, CAST(c AS UNSIGNED), 0))
184 SELECT * FROM (SELECT MAX(IFNULL(CAST(c AS UNSIGNED), 0)) FROM t1) AS te;
185 MAX(IFNULL(CAST(c AS UNSIGNED), 0))