我的表格结构如下:
mysql> desc services;
+----------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------------+-------------+------+-----+---------+-------+
| uuid | binary(16) | NO | PRI | NULL | |
| service_number | varchar(15) | YES | UNI | NULL | |
| mobile_imsi | varchar(15) | YES | UNI | NULL | |
| mobile_uid | varchar(10) | YES | UNI | NULL | |
| account_uuid | binary(16) | YES | MUL | NULL | |
| create_date | bigint(20) | YES | | NULL | |
| service_provider_id | varchar(4) | YES | | NULL | |
| service_provider | varchar(10) | YES | | NULL | |
| service_carrier_code | varchar(2) | YES | | NULL | |
| service_technology | varchar(10) | YES | | NULL | |
| mobile_msa | char(2) | YES | | NULL | |
| mica_acct_seq | varchar(4) | YES | | NULL | |
| payment_type | char(1) | YES | MUL | NULL | |
| price_plan | varchar(20) | YES | | NULL | |
| strategic_flag | bit(1) | YES | | NULL | |
| app_term_sms_flag | bit(1) | YES | | NULL | |
| modify_date | bigint(20) | YES | | NULL | |
| ported_flag | bit(1) | YES | | NULL | |
| prbt_barred_flag | bit(1) | YES | | NULL | |
+----------------------+-------------+------+-----+---------+-------+
19 rows in set (0.02 sec)
首先查询:
mysql> select service_number, mobile_imsi, hex(ported_flag) from services where hex(ported_flag) is not null and mobile_imsi is null;
Empty set (0.01 sec)
第二次查询:
mysql> select service_number, mobile_imsi, hex(ported_flag) from services where hex(ported_flag) is not null and ifnull(mobile_imsi,0) = '0';
+----------------+-------------+------------------+
| service_number | mobile_imsi | hex(ported_flag) |
+----------------+-------------+------------------+
| 0411720032 | NULL | 1 |
| 0419269667 | NULL | 1 |
| 0400000040 | NULL | 1 |
+----------------+-------------+------------------+
3 rows in set (1.58 sec)
第一个导致MySQL没有返回结果的查询是什么?我的预感是查询中的BIT字段在某种程度上是原因的一部分,但我不明白为什么这里的IFNULL函数允许它返回正确的结果集,而一个普通的旧“IS NULL”操作似乎失败了。
答案 0 :(得分:0)
mysql中的BIT类型太过错误。最好使用Tinyint(1)。对于布尔的所有事情,更好的tinyint(1)(或枚举(' Y',' N')。
试试并告诉我们