0

I'm trying to get the count of country visit on my site. I have a SQL table with uid, country and date. I'm then trying to pull count from SQL where I need the count in ordered array like

  • US - 53
  • UK - 47
  • CA - 45
  • and so on

It's been far to long time since I've played with SQL queries and I believe its my GROUP BY that fails.

SELECT COUNT(cfCountry) AS count FROM countryTracking GROUP BY cfCountry

But this just returns:

  • 8
  • 4
  • 47
  • 2
  • 4
  • 2
  • and so on

How do I make it return the count of the country in ordered with, plus the country in front?

GeekCoder
  • 25
  • 11

3 Answers3

0

You can try to add a count find like this

SELECT 
    country,
    COUNT(country) as count
FROM countryTracking
GROUP BY country
ORDER BY COUNT(country)
MZaragoza
  • 10,108
  • 9
  • 71
  • 116
Rabid Penguin
  • 1,084
  • 9
  • 22
0
SELECT COUNT(cfCountry) AS COUNT,
       cfCountry
FROM countryTracking
GROUP BY cfCountry
ORDER BY COUNT DESC;
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
Calvin
  • 605
  • 10
  • 26
-1

Simply adding the field you want to show alongside the count should show this in your resultset.

SELECT cfCountry, COUNT(cfCountry) AS count
FROM countryTracking c
GROUP BY cfCountry
Xamthi
  • 34
  • 6