PDA

View Full Version : یافتن ماکزیمم تعداد یک فیلد



Developer Programmer
دوشنبه 02 دی 1387, 18:19 عصر
میخوام اسامی کشور و ماکزیمم تعداد اون کشور رو بدست بیارم


Select Country , max(P)
From Customers,
( Select count(country) as p
from customers
group by country) as t

Column 'Customers.Country' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.

AminSobati
دوشنبه 02 دی 1387, 22:17 عصر
به نظر میرسه 2 کوئری متفاوت مورد نظر هستش. "اسامی کشور" یک لیست خواهد بود ولی ماکزیمم Scalar Value هست. میشه در یک کوئری ترکیب کرد اما معنی میده؟

تولائی
سه شنبه 03 دی 1387, 10:29 صبح
Select c.country, count(c.country) as p
from customers c
group by c.country
having count(c.country) =
(select max(p) from
(
Select c.country, count(c.country) as p
from customers c
group by c.country
) t)