表tb
有一字段
address
汇川区上海办交通居3-95
汇川区上海办交通居4-96
汇川区上海办荷花池居11组2号
汇川区上海办荷花池居12组3号
汇川区上海办茅草东居6组53号
汇川区上海办茅草东居7组54号
汇川区上海办荷花池居11组2号
汇川区上海办荷花池居12组3号
...
怎样用sql语句得到
address
汇川区上海办交通居
汇川区上海办荷花池居
汇川区上海办茅草东居
...

解决方案 »

  1.   

    declare @t table(address varchar(50))
    insert into @t select '汇川区上海办交通居3-95'
    union all select '汇川区上海办交通居4-96'
    union all select '汇川区上海办荷花池居11组2号'
    union all select '汇川区上海办荷花池居12组3号'
    union all select '汇川区上海办茅草东居6组53号'
    union all select '汇川区上海办茅草东居7组54号'
    union all select '汇川区上海办荷花池居11组2号'
    union all select '汇川区上海办荷花池居12组3号'select left(address,patindex('%[0-9]%',address)-1) from @t group by left(address,patindex('%[0-9]%',address)-1) select distinct left(address,patindex('%[0-9]%',address)-1)  from @t