分组求和问题 called_station_id 字段 查询出结果 0×××××××× 和 00××××××××(首数字相同 尾数和位数不一定)需要将0……和00……分组并求和 怎么处理? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select sum(value)from tbgroup by left(col,2) ...........group by left(called_station_id , 1 )union all ........group by left(called_station_id , 2) select len(replace(called_station_id,'0',''))from tagroup by len(replace(called_station_id,'0','')) 按这个分组:len(replace(called_station_id,'0','')) declare @t table(col varchar(10))insert @t select '0AAAAAAAAA'insert @t select '0AAAAAAAAA'insert @t select '00AAAAAAAA'insert @t select '00AAAAAAAA'insert @t select '00AAAAAAAA'insert @t select '00AAAAAAAA'insert @t select '0000AAAAAA'insert @t select '0000AAAAAA'select len(replace(col,'0','')),col,count(1) as cntfrom @tgroup by len(replace(col,'0','')),col/* col cnt ----------- ---------- ----------- 6 0000AAAAAA 28 00AAAAAAAA 49 0AAAAAAAAA 2(所影响的行数为 3 行)*/ declare @t table(col varchar(10)) insert @t select '0AAAAAAAAA' insert @t select '0AAAAAAAAA' insert @t select '00AAAAAAAA' insert @t select '00AAAAAAAA' insert @t select '00AAAAAAAA' insert @t select '00AAAAAAAA' insert @t select '0000AAAAAA' insert @t select '0000AAAAAA' select len(replace(col,'0','')),col,count(1) as cnt from @t group by len(replace(col,'0','')),col /* col cnt ----------- ---------- ----------- 6 0000AAAAAA 2 8 00AAAAAAAA 4 9 0AAAAAAAAA 2 (所影响的行数为 3 行) */ 求sql 日期难题 数据库代码 Statement st=con.createStatement()不执行的问题 复制数据 时遇到的问题,100分 少记录变成多条记录问题,用一条SQL语句应该怎么写? MS SQL帮助都正确么? 求返回结果 动态SQL赋值 文本型数据比较,欢迎讨论~~ 如何区分是汉字还是字母(1个字节和2个字节)? VC+ADO访问SQL的问题 ·!·!急·!·! 触发器
from tb
group by left(col,2)
group by left(called_station_id , 1 )union all ........
group by left(called_station_id , 2)
from ta
group by len(replace(called_station_id,'0',''))
insert @t select '0AAAAAAAAA'
insert @t select '0AAAAAAAAA'
insert @t select '00AAAAAAAA'
insert @t select '00AAAAAAAA'
insert @t select '00AAAAAAAA'
insert @t select '00AAAAAAAA'
insert @t select '0000AAAAAA'
insert @t select '0000AAAAAA'
select len(replace(col,'0','')),col,count(1) as cnt
from @t
group by len(replace(col,'0','')),col/*
col cnt
----------- ---------- -----------
6 0000AAAAAA 2
8 00AAAAAAAA 4
9 0AAAAAAAAA 2(所影响的行数为 3 行)*/
insert @t select '0AAAAAAAAA'
insert @t select '0AAAAAAAAA'
insert @t select '00AAAAAAAA'
insert @t select '00AAAAAAAA'
insert @t select '00AAAAAAAA'
insert @t select '00AAAAAAAA'
insert @t select '0000AAAAAA'
insert @t select '0000AAAAAA'
select len(replace(col,'0','')),col,count(1) as cnt
from @t
group by len(replace(col,'0','')),col /*
col cnt
----------- ---------- -----------
6 0000AAAAAA 2
8 00AAAAAAAA 4
9 0AAAAAAAAA 2 (所影响的行数为 3 行) */