spark统计
http://www.myexception.cn/sql/2004512.html
http://blog.csdn.net/ssw_1990/article/details/52220466
http://www.tuicool.com/articles/uIRZFv
http://mt.sohu.com/20160514/n449468405.shtml
http://blog.csdn.net/asongoficeandfire/article/details/21490101
http://confluence.jetbrains.com/display/IntelliJIDEA/Working+with+Scala+Console
http://my.oschina.net/jamesju/blog/83659
经过资料查询,做几个实验。
基本与sql的实现方式一致,方便理解。
第一步 实现分析
所有订单中每年最畅销货品:
1、求出每年每个货品的销售金额
scala>select c.theyear,b.itemid,sum(b.amount) as sumofamount from tbStock a join tbStockDetail b on a.ordernumber=b.ordernumber join tbDate c on a.dateid=c.dateid group by c.theyear,b.itemid
2、求出每年单品销售的最大金额
scala>select d.theyear,max(d.sumofamount) as maxofamount from (select c.theyear,b.itemid,sum(b.amount) as sumofamount from tbStock a join tbStockDetail b on a.ordernumber=b.ordernumber join tbDate c on a.dateid=c.dateid group by c.theyear,b.itemid) d group by d.theyear
3、求出每年与销售额最大相符的货品就是最畅销货品
scala>select distinct e.theyear,e.itemid,f.maxofamount from (select c.theyear,b.itemid,sum(b.amount) as sumofamount from tbStock a join tbStockDetail b on a.ordernumber=b.ordernumber join tbDate c on a.dateid=c.dateid group by c.theyear,b.itemid) e join (select d.theyear,max(d.sumofamount) as maxofamount from (select c.theyear,b.itemid,sum(b.amount) as sumofamount from tbStock a join tbStockDetail b on a.ordernumber=b.ordernumber join tbDate c on a.dateid=c.dateid group by c.theyear,b.itemid) d group by d.theyear) f on (e.theyear=f.theyear and e.sumofamount=f.maxofamount) order by e.theyear
第二步 实现SQL语句
scala>hiveContext.sql("select distinct e.theyear,e.itemid,f.maxofamount from (select c.theyear,b.itemid,sum(b.amount) as sumofamount from tbStock a join tbStockDetail b on a.ordernumber=b.ordernumber join tbDate c on a.dateid=c.dateid group by c.theyear,b.itemid) e join (select d.theyear,max(d.sumofamount) as maxofamount from (select c.theyear,b.itemid,sum(b.amount) as sumofamount from tbStock a join tbStockDetail b on a.ordernumber=b.ordernumber join tbDate c on a.dateid=c.dateid group by c.theyear,b.itemid) d group by d.theyear) f on (e.theyear=f.theyear and e.sumofamount=f.maxofamount) order by e.theyear").collect().foreach(println)
spark统计的更多相关文章
- Spark——统计文本中单词出现的次数
示例一:统计所有单词出现的次数 1.在本地创建文件并上传到hdfs中 #vin data.txt //将文件上传到hadoop的根目录下 #hdfs dfs -put data.txt / 2.在sp ...
- Ubuntu安装Hadoop与Spark
更新apt 用 hadoop 用户登录后,我们先更新一下 apt,后续我们使用 apt 安装软件,如果没更新可能有一些软件安装不了.按 ctrl+alt+t 打开终端窗口,执行如下命令: sudo a ...
- 【慕课网实战】Spark Streaming实时流处理项目实战笔记二之铭文升级版
铭文一级: 第二章:初识实时流处理 需求:统计主站每个(指定)课程访问的客户端.地域信息分布 地域:ip转换 Spark SQL项目实战 客户端:useragent获取 Hadoop基础课程 ==&g ...
- spark实战之网站日志分析
前面一篇应该算是比较详细的介绍了spark的基础知识,在了解了一些spark的知识之后相必大家对spark应该不算陌生了吧!如果你之前写过MapReduce,现在对spark也很熟悉的话我想你再也不想 ...
- Spark实战系列目录
1 Spark rdd -- action函数详解与实战 2 Spark rdd -- transformations函数详解与实战(上) 3 Spark rdd -- transformations ...
- Spark(二)—— 标签计算、用户画像应用
一.标签计算 数据 86913510 {"reviewPics":[],"extInfoList":null,"expenseList":n ...
- Docker搭建大数据集群 Hadoop Spark HBase Hive Zookeeper Scala
Docker搭建大数据集群 给出一个完全分布式hadoop+spark集群搭建完整文档,从环境准备(包括机器名,ip映射步骤,ssh免密,Java等)开始,包括zookeeper,hadoop,hiv ...
- Apache Drill - join HBase and RDBMs
HBase作为Nosql的常用系统之一,在很多大数据应用/平台中广泛使用.例如通过Spark统计后将结果存放到HBase中.通常统计结果还需要进一步和元数据或者字典表关联从而得到最终结果显示,这意味着 ...
- Spqrk笔记
LSM:Least square method 最小二乘法 ALS:Alternating Least Squares 交替最小二乘法 http://blog.csdn.net/dreamer2020 ...
随机推荐
- 继续畅通工程-Floyd
畅通工程续 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submiss ...
- 详解NTFS文件系统
一.分析NTFS文件系统的结构 当用户将硬盘的一个分区格式化为NTFS分区时,就建立了一个NTFS文件系统.NTFS文件系统同FAT32文件系统一样,也是用“簇”为存储单位,一个文件总是占用一个或多个 ...
- [办公自动化]一次制作、多场合多次使用的PPT
面试或汇报总结时,你可能需要制作一份PPT来介绍自己.但是这些场合你不一定能讲完所有的内容. 你可以尝试分1分钟.3分钟.5分钟.10分钟的版本来准备. 使用同一份PPT. 没错. 在office20 ...
- A trip through the Graphics Pipeline 2011_05
After the last post about texture samplers, we’re now back in the 3D frontend. We’re done with verte ...
- C# Dictionary已知value获取对应的key
1:循环遍历法,分为遍历key-value键值对和遍历所有key两种形式 2:使用Linq查询法 private void GetDictKeyByValue() { Dictionary<in ...
- Cocos2dx 多点触控
1 最容易忽略的东西,对于ios平台,须得设置glView的属性: [__glView setMultipleTouchEnabled:YES]; 2 如果调用CCLayer的方法setTouchEn ...
- Thinking in Java——笔记(8)
Polymorphism The polymorphic method call allows one type to express its distinction from another, si ...
- java FileLock
import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.nio.channels.FileChannel; import ...
- JS中的_proto_(2)
function God(){} function Foo(){ this.name="Foo~~"; } Foo.prototype = new God(); function ...
- Where is the Global.asax.cs file
I am using VS 2008. I have created a new Asp.net web site project from File->New->Website-> ...