我的查询:
select substr(name,1,1), name
from authors
group by name
order by name;
这是数据(MySQL)
1 C Chris
2 C Cary
3 D Doug
4 D Dave
5 D Drake
6 E Eli
7 E Elma
8 E Ezra
这就是我想要实现的目标。
1 C Chris
2 Cary
3 D Doug
4 Dave
5 Drake
6 E Eli
7 Elma
8 Ezra
感谢任何帮助。
答案 0 :(得分:1)
放手一搏......
select @substr := if(substr(@name,1,1) <> substr(name,1,1),substr(name,1,1) ,'') as groupedSubstr
,@name := name as name
from (
select name from authors
group by name
order by name
) a;