您可以为此创建一个函数:/**
* Split a string by string (Similar to the php function explode())
*
* @param VARCHAR(12) delim The boundary string (delimiter).
* @param VARCHAR(255) str The input string.
* @param INT pos The index of the string to return
* @return VARCHAR(255) The (pos)th substring
* @return VARCHAR(255) Returns the [pos]th string created by splitting the str parameter on boundaries formed by the delimiter.
* @{@example
* SELECT SPLIT_STRING('|', 'one|two|three|four', 1);
* This query
* }
*/DROP FUNCTION IF EXISTS SPLIT_STRING;CREATE FUNCTION SPLIT_STRING(delim VARCHAR(12), str VARCHAR(255),
pos INT)RETURNS VARCHAR(255) DETERMINISTICRETURN
REPLACE(
SUBSTRING(
SUBSTRING_INDEX(str, delim, pos),
LENGTH(SUBSTRING_INDEX(str, delim, pos-1)) + 1
),
delim, ''
);
将神奇的伪代码转换为使用此代码,您将拥有:SELECT e.`studentId`, SPLIT_STRING(',', c.`courseNames`, e.`courseId`)FROM...