怎样按字母和数字区别统计?

临窗飞飞 2011-12-13 04:53:59
原表
客户编码 销售额(元)
CUSA00001 10 ----------美国客户
CJPN00001 10 ----------日本客户
C05140001 5 ----------扬州客户
C02100001 5 ----------上海客户
CGER00001 8 ----------德国客户
C05510001 5 ----------合肥客户

都是客户,首字母都是C 第二位开始区分外国客户和国内客户
国内的用区号,也就是数字表示
国外的用国际三字码,也就是的认为开始有几位字母

怎样通过这个区别统计国际和国外的总销售额

结果输出

国内 15元
国外 28元


还请赐教

...全文
90 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
临窗飞飞 2011-12-14
  • 打赏
  • 举报
回复
其余前辈的语句,虽然有些小的地方不一样,都是可以执行的,而且是正确的,谢谢你们,从此我又学习了一个函数sbustring,很开心!
临窗飞飞 2011-12-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 acherat 的回复:]
SQL code


select (case when patindex(sbustring(客户编码,2,1),'1234567890')>0 then '国内' else '国外' end) as OO,
sum(销售额) as XX
from tb
group by (case when patindex(sbustring(客户编码,2,1),'12345678……
[/Quote]

您的语句报错哦!
1). [Microsoft][SQL Server Native Client 10.0][SQL Server]'sbustring' 不是可以识别的 内置函数名称。 2). [Microsoft][SQL Server Native Client 10.0][SQL Server]无法预定义语句。 '用户定义的值' (CSHS)
dawugui 2011-12-13
  • 打赏
  • 举报
回复
select case when substring(客户编码,2,1) between '0' and '9' then '国内' else '国外' end , sum(销售额) 销售额
from 原表
group by case when substring(客户编码,2,1) between '0' and '9' then '国内' else '国外' end
快溜 2011-12-13
  • 打赏
  • 举报
回复
select 客户=(case when substring(客户编码,2,1)>'9' then '国外' else '国内' end),
sum(销售额)
from tb group by (case when substring(客户编码,2,1)>'9' then '国外' else '国内' end)
--小F-- 2011-12-13
  • 打赏
  • 举报
回复
select
(case when substring(客户编码,2,1)>'9' then '国外' else '国内' end) as 客户,
sum(销售额)
from
tb
group by
(case when substring(客户编码,2,1)>'9' then '国外' else '国内' end)
-晴天 2011-12-13
  • 打赏
  • 举报
回复
select (case when substring(客户编码,2,1)>'9' then '国外' else '国内' end) as 客户,sum(销售额)
from tb group by (case when substring(客户编码,2,1)>'9' then '国外' else '国内' end)
AcHerat 2011-12-13
  • 打赏
  • 举报
回复

select (case when patindex(sbustring(客户编码,2,1),'1234567890')>0 then '国内' else '国外' end) as OO,
sum(销售额) as XX
from tb
group by (case when patindex(sbustring(客户编码,2,1),'1234567890')>0 then '国内' else '国外' end)

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧