2

我在 Access 2010 中有下表。

EQID Breaker Circuit Rating
1    A       One     1000
2    A       Two     1500
3    A       Three   500
4    A       Four    1000
5    B       One     1500
6    B       Two     2000

我想创建一个按断路器分组的查询,并显示最低评级和该评级的相关电路。我了解如何在不显示最低额定值的电路的情况下做到这一点。

我想要的查询结果是:

EQID Breaker Circuit Rating
1    A       Three   500
2    B       One     1500
4

2 回答 2

3

尝试这个:

SELECT a.*
FROM table AS a
INNER JOIN (
    SELECT Breaker, MIN(Rating) AS min_rating
    FROM table
    GROUP BY Breaker
) AS b
ON a.Breaker = b.Breaker AND
   a.Rating = b.min_rating;

SQLFiddle:http ://www.sqlfiddle.com/#!2/ea4fb/2

于 2013-08-26T15:38:31.293 回答
1

你可以试试下面:

SELECT t.EQID, t.Breaker, t.Circuit, t.Rating 
FROM test t 
INNER JOIN 
(
  SELECT a.Breaker, MIN(a.Rating) AS Rating 
  FROM test a 
  GROUP BY Breaker
 ) AS tmp 
ON tmp.Breaker = t.Breaker AND tmp.Rating = t.Rating;

Sql 小提琴演示:http ://sqlfiddle.com/#!2/fe796/19

于 2013-08-26T15:47:29.693 回答