In Old version of MySQL doesn't have any built in function to count number of occurrences of word in a string, so so we have to bit of tweak in your query to make this done in MySQL.
Now we have an option in MySQL To count the number of occurrences of a particular value in a MySQL table, you can use the COUNT function with a GROUP BY clause.
For example, if you have a table customers with a column region, you can use the following query to count the number of customers from each region:
SELECT region, COUNT(*)
FROM customers
GROUP BY region;
This will return a result set with one row for each region in the customers table, along with a count of the number of customers from that region.
You can also use a WHERE clause to count only the occurrences of a particular value. For example, to count the number of customers from the us-west-2, you can use the following query:
SELECT COUNT(*)
FROM customers
WHERE region = 'us-west-2';
This will return a single row with the count of customers from the us-west-2.
Comments (0)