我有一个表_1:
id custno
1 1
2 2
3 3
和一个table_2:
id custno qty
1 1 10
2 1 7
3 2 4
4 3 7
5 1 5
6 1 5
当我运行此查询以显示每个客户的最小订单数量时:
SELECT table_1.custno,table_2.qty
FROM table_1 LEFT OUTER JOIN table_2 ON table_1.custno = table_2.custno AND
qty = (SELECT MIN(qty) FROM table_2 WHERE table_2.custno = table_1.custno )
然后我得到这个结果:
custno qty
1 5
1 5
2 4
3 7
如何获得qty
per each的最小值custno
?
我怎么能这样做?
谢谢!