sql语句高手请进!!急!!!!!重谢!!

quake1007 2002-05-23 05:20:55
表中字段:
SBYF:格式--200101,200102......200112,现要求按季度求字段B的合计,请问SQL语句怎么写???
...全文
13 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wenlq 2002-05-27
select ( convert(int, substring(a1,5,2)) -1) / 3 + 1 as q, sum(a2) from aa
group by
( convert(int, substring(a1,5,2)) -1) / 3 + 1
回复
quake1007 2002-05-24
select (case when substring(SBYF,5,2) in ('01','02','03') then '01'
when substring(SBYF,5,2) in ('04','05','06') then '02'
when substring(SBYF,5,2) in ('07','08','09') then '03'
when substring(SBYF,5,2) in ('10','11','12') then '04'
end) as quarter,sum(fieldB)
from tablename
group by substring(SBYF,5,2)
回复
warning 2002-05-23
试试下面的语句,还没测试:)
select (case when substring(SBYF,5,2) in ('01','02','03') then '01'
when substring(SBYF,5,2) in ('04','05','06') then '02'
when substring(SBYF,5,2) in ('07','08','09') then '03'
when substring(SBYF,5,2) in ('10','11','12') then '04'
end) as quarter,sum(fieldB)
from tablename
group by quarter
回复
相关推荐
发帖
Sybase
创建于2007-09-28

2575

社区成员

Sybase相关技术讨论区
申请成为版主
帖子事件
创建了帖子
2002-05-23 05:20
社区公告
暂无公告