66的mysql代码,求关注
表格是上面张,输出了每个prod_id的前两个最小的quantity,下面这段代码看不懂,尤其是where里面<=2那一段,求大神解答
mysql> select prod_id,quantity
-> from orderitems-> where
-> ( select count(*) from orderitems a
-> where a.prod_id=orderitems.prod_id
-> and a.quantity<=orderitems.quantity)<=2
-> order by prod_id,quantity;
+---------+----------+
+---------+----------+
| prod_id | quantity |
+---------+----------+
| BNBG01 | 10 |
| BNBG01 | 100 |
| BNBG02 | 10 |
| BNBG02 | 100 |
| BNBG03 | 10 |
| BNBG03 | 100 |
| BR01 | 20 |
| BR01 | 100 |
| BR02 | 10 |
| BR03 | 5 |
| BR03 | 10 |
| RGAN01 | 5 |
| RGAN01 | 50 |
+---------+----------+
#笔试题目##Oracle##数据库工程师##MySQL#| prod_id | quantity |
+---------+----------+
| BNBG01 | 10 |
| BNBG01 | 100 |
| BNBG02 | 10 |
| BNBG02 | 100 |
| BNBG03 | 10 |
| BNBG03 | 100 |
| BR01 | 20 |
| BR01 | 100 |
| BR02 | 10 |
| BR03 | 5 |
| BR03 | 10 |
| RGAN01 | 5 |
| RGAN01 | 50 |
+---------+----------+