开发者

Matching 2 columns in a table

开发者 https://www.devze.com 2023-04-06 02:08 出处:网络
Ok, here is my data. Sault Ste. Marie, ON Sault Ste. Marie, MI Sault Ste. Marie, ON Sault Ste. Marie, MI I am trying to match and count the results.Current results are 4 for Sault Ste. Marie, ON wi

Ok, here is my data.

Sault Ste. Marie, ON
Sault Ste. Marie, MI
Sault Ste. Marie, ON
Sault Ste. Marie, MI

I am trying to match and count the results. Current results are 4 for Sault Ste. Marie, ON with the following code.

SELECT *, COUNT(`city`) AS `countrink`
FROM markers
GROUP BY `city`
HAVING `countrin开发者_StackOverflow社区k` >=2
ORDER BY `countrink` DESC

How can I match the 2 columns so the results read. Sault Ste. Marie, ON 2 Sault Ste. Marie, MI 2

Thanks


SELECT `city`, COUNT(`city`) AS `countrink`
FROM markers
GROUP BY `city`
HAVING `countrink` >= 2
ORDER BY `countrink` DESC

Although MySQL allows you to select columns outside of the GROUP BY clause, it produces undefined results. Therefore you can only reliably select city in addition to any aggregated columns.


This worked...

SELECT `city`, `prov`, COUNT(`city`) AS `countrink`
FROM markers
GROUP BY `city`, `prov`
HAVING `countrink` >=2
0

精彩评论

暂无评论...
验证码 换一张
取 消