2

我以前使用过这个查询:

SELECT * 
FROM stone_list 
WHERE type IN ('ALEXANDRITE','AMETHYST') 
   AND shape IN ('OVAL') ORDER BY type, shape

过去它对我有用,只是这次它做了一些非常奇怪的事情。当我只有一个 shape 值时IN,查询只返回 type isALEXANDRITE和 shape is 的结果OVAL,即使也有行type = AMETHYST and shape = OVAL

现在,当我添加第二个形状时,例如shape IN ('OVAL','ROUND'),它将返回两个type = ALEXANDRITE and type = AMETHYST和 for 的值shape = OVAL and shape = ROUND(因此,它按预期工作)。

真的胜过我。

有任何想法的人吗?

谢谢!

4

1 回答 1

1

查询没有任何问题,因此我只能假设您在问题中忽略或遗漏了某些内容。

mysql> select * from stone_list;
+----+-------------+--------+
| id | type        | shape  |
+----+-------------+--------+
|  1 | ALEXANDRITE | OVAL   |
|  2 | ALEXANDRITE | ROUND  |
|  3 | BASILIC     | OVAL   |
|  4 | AMETHYST    | SQUARE |
|  5 | AMETHYST    | ROUND  |
|  6 | AMETHYST    | OVAL   |
+----+-------------+--------+
6 rows in set (0.00 sec)


mysql> SELECT * FROM stone_list WHERE type IN ('ALEXANDRITE','AMETHYST') AND shape IN ('OVAL') ORDER BY type, shape
    -> ;
+----+-------------+-------+
| id | type        | shape |
+----+-------------+-------+
|  1 | ALEXANDRITE | OVAL  |
|  6 | AMETHYST    | OVAL  |
+----+-------------+-------+
2 rows in set (0.00 sec)


mysql> describe stone_list;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| type  | varchar(50)      | YES  |     | NULL    |                |
| shape | varchar(50)      | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
于 2012-04-09T01:55:14.527 回答