The default return type of IF() (which may matter when it is stored into a temporary table)
is calculated as follows.
如下图所示,但是似乎没有说明优先级
我们验证一下:虽然返回的10是个整型,但是其实返回的数据类型是浮点型的
mysql> create table t1 select if(1=1,10,10.1) score;
Query OK, 1 row affected (0.79 sec)
Records: 1 Duplicates: 0 Warnings: 0
再看如下例子,我们发现返回的10是一个varchar型的类型
mysql> create table t11 select if(1=1,10,'10.1') score;
Query OK, 1 row affected (0.38 sec)
Records: 1 Duplicates: 0 Warnings: 0
由此实验得出,其优先级是按照官方文档的那张表格自上而下,也就是字符串优先级最高
扫码关注