snibbe
snibbe

Reputation: 7

MySQL Query counting 2 columns as a pair

I've got a table with coordinates (latitude and longitude, so 2 columns) and some other tripdata. To locate a geographically position I need the combination of both columns, of course. So what I want to achieve is to count all kind of combinations in this table and group them. For this purpose I have to look at these 2 columns in a row like a "pair".

To count 1 column is not a problem. For example, I did it like this:

SELECT `longitude`, COUNT (*) AS `count`FROM ´tripdata`GROUP BY `longitude` ORDER BY `count`DESC;

But how to count it like a pair?

So the result should look like:

latitude | longitude | count

Thanks.

Upvotes: 0

Views: 47

Answers (1)

limen
limen

Reputation: 67

Try

SELECT `latitude `, `longitude`, COUNT (*) as `count`
FROM ´tripdata`
GROUP BY `latitude `, `longitude`
ORDER BY `count` DESC;

Upvotes: 1

Related Questions