I have a table(staffs_table) with the following data;
name profession
------------------------------
Corbin Human Resources|Accountant
Cort Programmer|Receptionist|Helpdesk
I want to count number of people per each profession so as my results to be as follows;
profession number_of_staffs
---------------------------------------
Human Resources 1
Accountant 1
Programmer 1
Receptionist 1
Helpdesk 1
I tried the following SQL query with no success;
SELECT profession, COUNT(*) AS number_of_staffs FROM staffs_table GROUP BY profession ORDER BY COUNT(*) DESC;
OUTPUT:
profession number_of_staffs
---------------------------------------------
Human Resources|Accountant 1
Programmer|Receptionist|Helpdesk 1
Also tried the following;
SELECT staffs_table.name,
SUBSTRING_INDEX(SUBSTRING_INDEX(staffs_table.profession, '|', numbers.n), '|', -1) profession
FROM
numbers INNER JOIN staffs_table
ON CHAR_LENGTH(staffs_table.profession)
-CHAR_LENGTH(REPLACE(staffs_table.profession, '|', ''))>=numbers.n-1
OUTPUT:
name profession
------------------------------
Corbin Human Resources
Corbin Accountant
Cort Programmer
Cort Receptionist
Cort Helpdesk
Thanks in advance!