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

如一字段有值:x001x003p005y0093分组结果应为.X=2,p=1,y=1
2024-12-21 20:56:17
推荐回答(5个)
回答1:

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

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

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

回答2:

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

回答3:

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

回答4:

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

回答5:

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