0
Product_Code  Month  Qty  Area  CustomerID
------------  -----  ---  ----  ----------
820300182     01     1    M1    100078
820300182     01     50   M1    100168
820300182     01     20   M1    100188
820300182     01     10   M1    100618
820300182     01     10   M1    100938
820300182     01     20   M1    100988
820300182     01     25   M1    110158

我想得到Qty最低限度customerID

例如,

Product_Code  Month  Qty  Area  CustomerID
------------  -----  ---  ----  ----------
820300182     01     1    M1    100078
4

2 回答 2

1

试试这个

Select Qty
from tableName
where CustomerID = ( select min(CustomerID) from tableName )
于 2012-06-30T08:32:44.477 回答
1

假设您要查找具有最低 CustomerId 的记录:

SELECT TOP 1 [Product_Code], [Month], [Qty], [Area], [CustomerID]
FROM [TABLE]
ORDER BY [CustomerId] ASC

但是,如果您需要找到数量最少的记录,则将订单更改为

ORDER BY [Qty] ASC
于 2012-07-01T19:15:19.333 回答