0

我只想显示最大价值的计数(LEG.LEG#),我该如何实现。我知道我可以使用 max 但在这种情况下如何使用 max。

询问,

select leg.T#,count(leg.LEG#) 
from trktripleg leg,trktrip trip 
WHERE leg.T#  = trip.T# AND trip.L#='10001' 
GROUP BY leg.T# 
ORDER by leg.T# ASC;

结果,

        T# COUNT(LEG.LEG#)
---------- ---------------
         1               3
         3               3
         8               3
        18               3
        21               3
        25               4
        26               3
        29               3
        35               4
        37               5
        39               3

        T# COUNT(LEG.LEG#)
---------- ---------------
        44               4
        57               4
        61               4
        62               3
        65               4
        71               5
        73               3
        75               5
        80               5
        90               4
        93               5

        T# COUNT(LEG.LEG#)
---------- ---------------
        97               5
        98               4
       101               4
       107               3


SQL> desc trktripleg
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------

 T#                                        NOT NULL NUMBER(10)
 LEG#                                      NOT NULL NUMBER(2)
 DEPARTURE                                 NOT NULL VARCHAR2(30)
 DESTINATION                               NOT NULL VARCHAR2(30)

SQL> desc trktrip
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------

 T#                                        NOT NULL NUMBER(10)
 L#                                        NOT NULL NUMBER(8)
 REG#                                      NOT NULL VARCHAR2(10)
 TRKTRIP_DATE                              NOT NULL DATE
4

1 回答 1

0
SELECT MAX(c)
FROM (SELECT leg.T#,COUNT(leg.LEG#) c
FROM trktripleg leg,trktrip trip 
WHERE leg.T#  = trip.T# AND trip.L#='10001' 
GROUP BY leg.T#);
于 2012-11-26T09:23:07.623 回答