为什么SELECT * FROM title_included = 0
返回一行?
mysql> SELECT * FROM person_task WHERE title_included = 0;
+----+----------+---------+----------+---------------------+----------+------------+-----------+----------+-----------------------+----------------+-------------+----------+---------+--------------+-----------------+-------------------+---------------+---------------------+---------+---------+-------------------+-------------+---------------------+---------------------+
| id | location | keyword | industry | years_of_experience | language | first_name | last_name | zip_code | title_included | title_excluded | title_scope | function | company | company_size | seniority_level | tenure_at_company | total_results | last_result_scraped | elapsed | is_done | last_page_scraped | total_pages | creation_time | scraping_time |
+----+----------+---------+----------+---------------------+----------+------------+-----------+----------+-----------------------+----------------+-------------+----------+---------+--------------+-----------------+-------------------+---------------+---------------------+---------+---------+-------------------+-------------+---------------------+---------------------+
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | Global IT procurement | 0 | CURRENT | 0 | 0 | C | 0 | 0 | 12 | 12 | 86.5676 | 0 | 1 | 1 | 2019-11-02 16:08:51 | 2019-11-02 15:12:34 |
+----+----------+---------+----------+---------------------+----------+------------+-----------+----------+-----------------------+----------------+-------------+----------+---------+--------------+-----------------+-------------------+---------------+---------------------+---------+---------+-------------------+-------------+---------------------+---------------------+
1 row in set (0.00 sec)
mysql> SELECT * FROM person_task WHERE title_included = "0";
Empty set (0.00 sec)
0
SELECT * FROM person_task WHERE title_included = 0
第一个查询返回一行。
“ 0”
SELECT * FROM person_task WHERE title_included = "0"
第二个查询不返回。
表
这是我的person_task表结构。title_included的类型是MEDIUMTEXT。
mysql> DESCRIBE person_task;
+---------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| location | mediumtext | YES | | NULL | |
| keyword | mediumtext | YES | | NULL | |
| industry | mediumtext | YES | | NULL | |
| years_of_experience | mediumtext | YES | | NULL | |
| language | mediumtext | YES | | NULL | |
| first_name | mediumtext | YES | | NULL | |
| last_name | mediumtext | YES | | NULL | |
| zip_code | mediumtext | YES | | NULL | |
| title_included | mediumtext | YES | | NULL | |
| title_excluded | mediumtext | YES | | NULL | |
| title_scope | mediumtext | YES | | NULL | |
| function | mediumtext | YES | | NULL | |
| company | mediumtext | YES | | NULL | |
| company_size | mediumtext | YES | | NULL | |
| seniority_level | mediumtext | YES | | NULL | |
| tenure_at_company | mediumtext | YES | | NULL | |
| total_results | mediumint(9) | YES | | NULL | |
| last_result_scraped | mediumint(9) | YES | | NULL | |
| elapsed | float | YES | | NULL | |
| is_done | tinyint(4) | YES | | NULL | |
| last_page_scraped | tinyint(4) | YES | | NULL | |
| total_pages | mediumint(9) | YES | | NULL | |
| creation_time | datetime | YES | | NULL | |
| scraping_time | datetime | YES | | NULL | |
+---------------------+--------------+------+-----+---------+----------------+
25 rows in set (0.00 sec)
WHERE title_included = 0
您正在将字符串与整数进行比较。这样做时,MySQL将字符串转换为数字数据类型。除非您的字符串是数字,否则结果为0。
WHERE title_included = "0"(注意:应为'0')
在这里,您正在进行字符串比较。会得到正常的结果
了解您的数据类型;在查询中传递正确的数据类型,以避免隐式转换。如果要比较字符串,请将其与
string
类型比较
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。