Union查询结果数据类型转换问题

博客讨论了在MySQL中使用Union查询时遇到的数据类型转换问题。文章指出,理论上数据类型应该按照低优先级向高优先级转换,但实际测试结果显示并非如此,引发作者对这一现象的疑惑和探讨。
摘要由CSDN通过智能技术生成

根据以下说法,数据由低优先级向高优先级转化:

When an operator combines two expressions of different data types, the rules for data type precedence specify that the data type with the lower precedence is converted to the data type with the higher precedence.

部分数据类型优先级顺序如下图:

用mysql进行测试,结果却不符合由低到高转换的说法:

mysql> select*from testu;
+---+---+
| a | b |
+---+---+
| 1 | a |
| 2 | b |
+---+---+
2 rows in set

mysql> create table `ttt` select `a` from `testU` union select `b` from `testU`;
Query OK, 4 rows affected
Records: 4  Duplicates: 0  Warnings: 0

mysql> select*from `ttt`;
+---+
| a |
+---+
| 1 |
| 2 |
| a |
| b |
+---+
4 rows in set
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值