sql中如何按某字段值的首字母分组?

来源:百度知道 编辑:UC知道 时间:2024/09/21 11:01:45
如一字段有值:
x001
x003
p005
y0093

分组结果应为.X=2,p=1,y=1

select count(*),left(a,1) from table group by left(a,1)

这里假设这个字段名称为a了,表名为table,

请根据你的实际情况修改一下即可.

设table1字段col1
select ..... from table1 group by left(col1,1)

select ..... from table1 group by subsrting(col1,1,1)

select * from table group by where id like 'x%'

我赞成muqiao520这们朋友的做法,很好