我想显示最大值的计数(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
答案 0 :(得分: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#);