MySQL:select所有数据,但如果包含'*',则显示最后四个字符
MySQL: select all the data but if contains ' * ', then show the last four characters
类似于:
SELECT IF( [call_history.callerid 包含 '*'], [如果包含,保留最后四个字符],[如果不包含,return ' '(不为空) ] ) 作为 'test'
从call_history
ORDER BY start DESC;
我建议阅读 MySQL 的 SQL 风格中内置的字符串函数的手册页:http://dev.mysql.com/doc/refman/5.7/en/string-functions.html
例如:
SELECT IF(LOCATE(callerid, '*'), SUBSTRING(callerid, -4), '') AS 'test'
FROM call_history
ORDER BY start DESC;
类似于:
SELECT IF( [call_history.callerid 包含 '*'], [如果包含,保留最后四个字符],[如果不包含,return ' '(不为空) ] ) 作为 'test'
从call_history
ORDER BY start DESC;
我建议阅读 MySQL 的 SQL 风格中内置的字符串函数的手册页:http://dev.mysql.com/doc/refman/5.7/en/string-functions.html
例如:
SELECT IF(LOCATE(callerid, '*'), SUBSTRING(callerid, -4), '') AS 'test'
FROM call_history
ORDER BY start DESC;