我有以下查询
SELECT (CASE WHEN cc.country IS NULL THEN dc.country ELSE cc.country END) AS Country,l.band FROM lotw l
OUTER LEFT JOIN CountryCode cc on cc.code = l.dxcc
OUTER LEFT JOIN DeleteCountry dc on dc.code = l.dxcc
WHERE l.DXCC > '' GROUP BY cc.Country,dc.country
产生以下结果
Country Band
Bonaire 15M
St. Maarten 40M
Aland Is. 20M
Alaska 15M
Andorra 80M
Antigua & Barbuda 10M
Argentina 10M
Aruba 10M
Ascension Is. 20M
Asiatic Russia 40M
Austral I. 40M
…………</p>
我需要得到的是每个乐队的计数?
Band Total
10M 50
20M 20
30M 5
所以我尝试了这个:
select Band,Count(Band) FROM(
SELECT (CASE WHEN cc.country IS NULL THEN dc.country ELSE cc.country END) AS Country,
l.band FROM lotw l
OUTER LEFT JOIN CountryCode cc on cc.code = l.dxcc
OUTER LEFT JOIN DeleteCountry dc on dc.code = l.dxcc
WHERE l.DXCC > '' GROUP BY cc.Country,dc.country
)group by Band
这几乎奏效了,但计数已关闭,例如 10M,计数应为 79,而它的计数为 27?
但是,如果我使用此查询并将其限制为 10M 它可以工作,但我只能得到一个波段:
select Band,Count(Band) FROM(
SELECT (CASE WHEN cc.country IS NULL THEN dc.country ELSE cc.country END) AS Country,
l.band FROM lotw l
OUTER LEFT JOIN CountryCode cc on cc.code = l.dxcc
OUTER LEFT JOIN DeleteCountry dc on dc.code = l.dxcc
WHERE l.DXCC > '' AND BAND = '10M' GROUP BY cc.Country,dc.country
)
不知道该怎么做。