日期:2014-05-17  浏览次数:20426 次

mysql如何以英文单词的首字母group by???
有一字段   内容都是英文,我如何以英文单词的首字母group   by这个字段??
没有头绪,谢谢了!


------解决方案--------------------
select *, upper(left(englishword,1)) as c
from tablename
group by c
------解决方案--------------------
SELECT evalue
FROM tablename
GROUP BY left( upper(rtrim( ltrim( evalue ) )) , 1 )
------解决方案--------------------
SELECT substr(字段内容,1,1) FROM tablename
GROUP BY substr(字段内容,1,1) HAVING (加一些你自己需要的限制条件)
------------------------------------
可能我对你的问理解的不正确,请把问题说的略为详细一些哈,谢谢!
其实这种问题,完全可以自己在去Google上面搜一下,那样效率会更高一下。

------解决方案--------------------
mysql> select * from a;
+-----+------------+
| aid | title |
+-----+------------+
| 1 | csdn |
| 2 | csdn |
| 3 | 666 |
| 4 | 343 |
| 5 | (NU |
| 6 | 343 |
| 7 | fgh |
| 8 | 676 |
| 9 | csdn |
| 10 | csdn |
| 11 | aaa[A]abcd |
| 89 | sfsdfsaf |
+-----+------------+
12 rows in set (0.00 sec)

mysql> select * from a order by substring(lcase(title),1,1) ;
+-----+------------+
| aid | title |
+-----+------------+
| 5 | (NU |
| 4 | 343 |
| 6 | 343 |
| 3 | 666 |
| 8 | 676 |
| 11 | aaa[A]abcd |
| 1 | csdn |
| 2 | csdn |
| 9 | csdn |
| 10 | csdn |
| 7 | fgh |
| 89 | sfsdfsaf |
+-----+------------+
12 rows in set (0.01 sec)