Foxtable(狐表)用户栏目专家坐堂 → 请教SQL语句写法


  共有13259人关注过本帖树形打印复制链接

主题:请教SQL语句写法

帅哥哟,离线,有人找我吗?
狐狸爸爸
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2010/12/10 17:53:00 [显示全部帖子]

select a.区,sum(b.销售金额),sum(b.销售成本),sum(b.销售税) from jcxx a,xssj_2009 b where a.sku=b.sku and b.日期 between '2009-12-1' and '2009-12-31'  or b.日期 between '2010-1-1' and '2010-1-31' group by a.区

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2010/12/11 0:21:00 [显示全部帖子]

Select 区, sum(销售金额), Sum(销售成本), Sum(销售额) From

(select a.区 as 区, sum(b.销售金额) as 销售金额 ,sum(b.销售成本) as 销售成本, sum(b.销售税) as 销售额 from jcxx a,xssj_2009 b where a.sku=b.sku and b.日期 between '2009-12-1' and '2009-12-31' group by a.区 
UNION ALL

select a.区 as 区 ,sum(b.销售金额) as 销售金额, sum(b.销售成本) as 销售成本, sum(b.销售税) As 销售额 from jcxx a,xssj_2010 b where a.sku=b.sku and b.日期 between '2010-1-1' and '2010-1-31' group by a.区)

Group by 区


 回到顶部