I have this data in my database.
id | company_id | referrer
001 | 001 | https://google.com
002 | 001 | https://riot.com
003 | 001 | https://google.com
004 | 002 | https://vimeo.com
005 | 002 | https://yahoo.com
006 | 003 | https://yahoo.com
I want to get the number of times a referrer has repeated per company_id. A company has many referrer, but I only want to get the highest referrer that repeated in the data.
So the result would be something like this:
company_id | referrer | nRepeat
001 | https://google.com | 2
002 | https://yahoo.com | 2
I tried this code:
SELECT company_id,
referrer,
Count(referrer) AS viewCount
FROM `my_table`
GROUP BY company_id
ORDER BY viewcount DESC
This query seems to be wrong.
Apologies if I explain it poorly, let me know if you have questions.
Any tips or help on this? Your help is greatly appreciated! Thanks!