so I got a column with hundreds of different first names and another column with 7 different neighborhoods that repeat multiple times.
I want to check what are the most common names for each neighborhood. How would I go about it?
Thanks and I hope I made my question clear enough.
I tried the below, and got this error - SQL Error: Syntax error: Encountered " "COUNT" "Count "" at line 8, column 5. Was expecting: EOF
SELECT
host_name, neighbourhood_group,
COUNT(*) AS Ct
FROM AB_NYC_2019
GROUP BY
host_name,
neighbourhood_group,
Max Count AS
(
SELECT
*,
MAX(Ct) OVER
(
PARTITION BY neighbourhood_group
) AS MaxCt
FROM Counts
)
SELECT
neighbourhood_group,
host_name
FROM MaxCounts
WHERE Ct = MaxCt;
select * from
(select host_name,neighbourhood_group, RANK() OVER (PARTITION BY neighbourhood_group order by c desc) as RN
from(select host_name,neighbourhood_group,count(*) as c
from AB_NYC_2019 group by host_name,neighbourhood_group)m)n where
RN=1;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.