Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 删除列-SQL中的某个字符后的计数_Mysql_Sql_Group By_Count_Substring - Fatal编程技术网

Mysql 删除列-SQL中的某个字符后的计数

Mysql 删除列-SQL中的某个字符后的计数,mysql,sql,group-by,count,substring,Mysql,Sql,Group By,Count,Substring,我有一个包含以下数据的tablestaffs_表 name profession ------------------------------ Corbin Human Resources|Accountant Cort Programmer|Receptionist|Helpdesk 我想计算每个职业的人数,结果如下: profession number_of_staffs -------

我有一个包含以下数据的tablestaffs_表

name               profession
------------------------------
Corbin             Human Resources|Accountant
Cort               Programmer|Receptionist|Helpdesk
我想计算每个职业的人数,结果如下:

profession             number_of_staffs
---------------------------------------
Human Resources            1
Accountant                 1 
Programmer                 1
Receptionist               1
Helpdesk                   1
我尝试了以下SQL查询,但没有成功

SELECT profession, COUNT(*) AS number_of_staffs FROM staffs_table GROUP BY profession ORDER BY COUNT(*) DESC;
输出:

还尝试了以下方法

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
输出:

提前谢谢

选择jsontable.profession,COUNTjsontable.profession人数 从桌上 交叉连接JSON_TABLE CONCAT“[”,replaceStaff_TABLE.professional“|”,,,,,,”], $[*]列VARCHAR254路径$ 如可交谈的 按jsontable.profession分组;
这回答了你的问题吗?指定您的MySQL版本。修复您的数据模型!不要在一列中存储多个值@安基巴吉感谢您的答复。这是不同的。您所引用的问题,仅在删除‘’|’’后显示结果,而不显示计数。我的问题是对计算感兴趣。所以一旦你把它分成几行,你就可以启动一个cont函数来计算关键字。谢谢你的回复。我将jsontable.profession编辑为staff_table.profession并尝试执行,但在JSON_table附近显示错误,表示该表不可用exist@canonngirwa我为什么???为什么需要编辑正确的查询?@Canongirwa这是一个关于错误的故事。显示完整的错误消息,没有版本和限制。`1064-您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,了解第3行“@Canongirwa您的MySQL版本是什么?”?
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
name               profession
------------------------------
Corbin             Human Resources
Corbin             Accountant
Cort               Programmer
Cort               Receptionist
Cort               Helpdesk