MySql 条件简短描述 [英] MySql conditional short descriptions

查看:40
本文介绍了MySql 条件简短描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我在一个 SQL 查询中获取类似 google 的 url 描述.

Please help me fetching google like url descriptions in just one SQL query.

参见示例

如果描述大于固定的字符限制,比如 100 个字符,然后附加...",否则显示完整的描述.

If description is greater than a fixed limit of characters say 100 characters then append '...' otherwise show the complete description.

我当前的 SQL 查询是这样的:

My current SQL query is this:

 SELECT post_id, CONCAT( LEFT( post_text, 50 ) , '...' ) AS text FROM posts

请提出解决方案...

推荐答案

if( length( post_text ) > 50, CONCAT( LEFT( post_text, 47 ) , '...' ), post_text )

这篇关于MySql 条件简短描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆