一. help_topic
help_topic是mysql库下的一张表
使用help_topic时为了解决行转列的问题,出现上面错误(
[Err] 1142 - SELECT command denied to user 'hunan'@'10.21.36.48' for table 'help_topic')是因为用户没有这张表的权限。
解决方法:
可以执行该SQL:GRANT SELECT ON mysql.help_topic TO 'autochain_uat'@'localhost'(给用户赋权限);
取消用户权限SQL:REVOKE SELECT ON mysql.help_topic FROM 'autochain_uat'@'localhost';
也可以根据下图步骤操作:
二. 场景
username | tags |
王五 | 10,11,12 |
龙大 | 12,13,14 |
sql:
select a.username,substring_index(substring_index(a.tags,',',b.help_topic_id+1),',',-1) tag
from USER_TAG a join
mysql.help_topic b
on b.help_topic_id < (length(a.tags) - length(replace(a.tags,',',''))+1)
order by username
结果:
username | tag |
王五 | 10 |
王五 | 11 |
王五 | 12 |
龙大 | 12 |
龙大 | 13 |
龙大 | 14 |