使用 「分組依據」:
select a.pid,a.city,a.countryCode, b.zipEnabled,b.english, a.c from (
SELECT a.pid,a.city,a.countryCode, count(*) c
FROM geoWorld AS a
JOIN geoCountry AS b ON a.countryCode=b.countryCode
WHERE a.city IN ("free","dating","donvale","australia")
group by a.pid,a.city,a.countryCode
) AS a JOIN geoCountry AS b ON a.countryCode=b.countryCode
order by c desc
或
SELECT a.pid,a.city,a.countryCode,b.zipEnabled,b.english,
(select count(*) from geoCountry c where c.countryCode = a.countryCode) ct
FROM geoWorld AS a
JOIN geoCountry AS b ON a.countryCode=b.countryCode
WHERE
a.city IN ("free","dating","donvale","australia")
order by ct desc
,或者如果你 「需要返回,在報表匹配2個值的行」 具有使用的語句,例如:
select a.pid,a.city,a.countryCode, b.zipEnabled,b.english, a.c from (
SELECT a.pid,a.city,a.countryCode, count(*) c
FROM geoWorld AS a
JOIN geoCountry AS b ON a.countryCode=b.countryCode
WHERE a.city IN ("free","dating","donvale","australia")
group by a.pid,a.city,a.countryCode
having c=2
) AS a JOIN geoCountry AS b ON a.countryCode=b.countryCode
order by c desc
'集團通過a.city訂購數(a.city)desc'應該解決這個問題。 –