MySQL 删除 order by 子句之前的空格
我有一张满是“标题”的桌子,我想按标题排序。问题是很多标题前都有空格。我正在考虑编写一个 php 脚本来解决这一切(超级简单),但我很好奇我该怎么做:
SELECT * FROM products ORDER BY title
但同时修剪标题,这样它就不会在空白处排序。所有这些都在同一个查询中,无需更改数据。天哪,我希望我说得有道理。
所以我真的正在寻找一个 mysql 解决方案。就其价值而言,我使用 Zend_Db,因此使用它的解决方案会更好,但我可以直接管理 MySQL。
I have a table full of "title" that I want to order by title. Problem is a lot of them have a empty space before the title. I am thinking of writting a php script to fix it all (super easy) but I was curious how could I do:
SELECT * FROM products ORDER BY title
But at the same time trimming the title so it doesnt order on the empty space. All in the same query without changing the data. God I hope I make sense.
So I am really looking for a mysql solution to this. For what its worth I use Zend_Db so a solution using that would be even better but I can manage straight MySQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 TRIM 功能:
应该可以了!
You can use the TRIM function:
That ought to do it!
我会回答自己,因为我的问题的确切解决方案是:
我仍然会接受科迪克里格的答案,因为他做到了,所以我找到了我的解决方案。
这是 Zend_Db 的答案:
I'll answer myself because the exact solution to my question is:
I'll still accept codykrieger's answer because he made it so I found my solution.
Here is the Zend_Db answer:
纯 SQL 查询如下所示:
A pure SQL query would look like this: