截取字符串,再进行group by ,取记录数大于0的,再用having count(*)
查询CORP_NUMBER的前4位相同的并且记录条数大于0的记录
select count(*),LEFT(tb_yhpc_cure.CORP_NUMBER,4) num from tb_yhpc_cure where tb_yhpc_cure.CORP_NUMBER is not null and tb_yhpc_cure.CORP_NUMBER !='' group by LEFT(tb_yhpc_cure.CORP_NUMBER,4) HAVING COUNT(*) > 1
之前sql
SELECT count(*) as valuess ,tb_yhpc_cure.CORP_NUMBER num from tb_yhpc_cure where tb_yhpc_cure.CORP_NUMBER is not null and tb_yhpc_cure.CORP_NUMBER !='' group by tb_yhpc_cure.CORP_NUMBER