求PB大神帮忙!现有A表,里面有JE和date字段,date字段是日期格式即11/02/2014,我想用graph显示
显示每个季度或者每个月的销售总额sum(Je),请问我该怎么写SQL语句呢?求各位大神帮帮!谢谢了...
显示每个季度或者每个月的销售总额sum(Je),请问我该怎么写SQL语句呢?求各位大神帮帮!谢谢了
展开
1个回答
2014-08-13 · 知道合伙人软件行家
关注
展开全部
这个是按月的:
SELECT
CAST(YEAR(date) as varchar) + '-' + CAST(MONTH(date) as varchar) AS date,
SUM( je ) AS je
FROM
a
GROUP BY
CAST(YEAR(date) as varchar) + '-' + CAST(MONTH(date) as varchar)
这个是按季度的:
Select Case when month(date) in (1,2,3) then '一季度'
when month(date) in (4,5,6) then '二季度'
when month(date) in (7,8,9) then '三季度'
when month(date) in (10,11,12) then '四季度' end ,
sum(je)
from a
group by Case when month(date) in (1,2,3) then '一季度'
when month(date) in (4,5,6) then '二季度'
when month(date) in (7,8,9) then '三季度'
when month(date) in (10,11,12) then '四季度' end
这边都没有对年份做处理,如果你的数据跨年要按年份过滤一下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询