开发者社区> 问答> 正文

为什么SELECT * FROM title_included = 0返回一行?

为什么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)

展开
收起
1476984019861890 2019-11-25 21:22:34 851 0
1 条回答
写回答
取消 提交回答
  • WHERE title_included = 0
    

    您正在将字符串与整数进行比较。这样做时,MySQL将字符串转换为数字数据类型。除非您的字符串是数字,否则结果为0。

    WHERE title_included = "0"(注意:应为'0')
    

    在这里,您正在进行字符串比较。会得到正常的结果

    了解您的数据类型;在查询中传递正确的数据类型,以避免隐式转换。如果要比较字符串,请将其与string类型比较

    2019-11-25 21:27:41
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Semantic Search--Fast Results from Large,Foreign Language Corpora 立即下载
A Developer’s View into Spark\'s Memory Model 立即下载
Building Data Products on 立即下载