Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

MySQL String Exercises: Write a query to get the job_id and related employee's id

MySQL String: Exercise-1 with Solution

Write a query to get the job_id and related employee's id.

Expected Output

Sample table: employees


Code:

SELECT job_id, GROUP_CONCAT(employee_id, ' ')  'Employees ID' 
FROM employees GROUP BY job_id;

Sample Output:

job_id		Employees ID
AC_ACCOUNT	206
AC_MGR		205
AD_ASST		200
AD_PRES		100
AD_VP		101 ,102
FI_ACCOUNT	109 ,110 ,111 ,112 ,113
FI_MGR		108
HR_REP		203
IT_PROG		103 ,104 ,105 ,106 ,107
MK_MAN		201
MK_REP		202
PR_REP		204
PU_CLERK	115 ,116 ,117 ,118 ,119
PU_MAN		114
SA_MAN		145 ,146 ,147 ,148 ,149
SA_REP		150 ,151 ,152 ,153 ,154 ,155 ,156 ,157 ,158 ,159 ,160 ,161 ,162 ,163 ,164 ,165 ,166 ,167 ,168 ,169 ,170 ,171 ,172 ,173 ,174 ,175 ,176 ,177 ,178 ,179
SH_CLERK	180 ,181 ,182 ,183 ,184 ,185 ,186 ,187 ,188 ,189 ,190 ,191 ,192 ,193 ,194 ,195 ,196 ,197 ,198 ,199
ST_CLERK	125 ,126 ,127 ,128 ,129 ,130 ,131 ,132 ,133 ,134 ,135 ,136 ,137 ,138 ,139 ,140 ,141 ,142 ,143 ,144
ST_MAN		120 ,121 ,122 ,123 ,124

MySQL Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous:MySQL string
Next:Write a query to update the portion of the phone_number in the employees table, within the phone number the substring '124' will be replaced by '999'.

What is the difficulty level of this exercise?