0

enter image description here

when I use this query

mysql> select movieid from rating where stars < any (select stars from rating where 

movieid=103);

the output is as below

movieid 

 101 
 108    
 104 

when I execute the below query, the results seems to be the same. Why is that?

> mysql> select movieid,stars from rating where stars <all (select stars
> from rating where movieid=103);

+---------+-------+
| movieid | stars |
+---------+-------+
|     101 |     2 |
|     108 |     2 |
|     104 |     2 |
+---------+-------+

shouldn't the all keyword give back the results which are less than to the stars value 2? which in this case would be an empty set.

here is a capture

enter image description here

4

2 回答 2

1

The data in the capture is different from the data you posted earlier, you have 3 stars for both rows with movieid = 103 (as opposed to 3 and 2)

As for the first data you provided:

First query with `any' is equivalent to:

select movieid from rating where stars < 2 OR stars < 3

and the result is:

101
103
108
104

The second query is equivalent to:

select movieid from rating where stars < 2 AND stars < 3

and the result is an empty set.

For the screen capture data:

Both queries are equivalent to:

select movieid from rating where stars < 3

and the result is:

101
108
104
于 2013-04-28T15:42:18.917 回答
0

I don't know, but if i were writing this I would have done something like:

/* is this what you want by "any" */
select movieid,stars from rating where stars < (select max(stars) from rating where movieid=103);

/* is this what you want by "all" */
select movieid,stars from rating where stars < (select min(stars) from rating where movieid=103);

demo

于 2013-04-28T15:19:35.253 回答