方式一: # select # uid, # if(char_length(nick_name)>13,concat(substring(nick_name,1,10),'...'),nick_name) # from # user_info # where char_length(nick_name)>=10 方式二: select uid, case when char_length(nick_name)>13 then concat(left(nick_name,10),'...') else nick_name end from user_info where char_length(nick_name)>10
考核知识点:if、case when then 条件的使用,length、char_length 的使用及区别
case when 表达式 then ... when ....then ...else ... end
char_length:返回字符的个数, length:返回的是字节个数