表結構:oop
ddl:hadoop
Create Table |
CREATE TABLE `ord` ( `id` int(11) NOT NULL AUTO_INCREMENT, `date` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 |
Create Table |
|
Create Table |
CREATE TABLE `prd` ( `id` int(11) NOT NULL AUTO_INCREMENT, `type` int(11) DEFAULT NULL, `desc` varchar(30) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 |
需求:獲取一週內,同品類產品天天的售賣數量it
答案:io
SELECT DATE_FORMAT(`ord`.`date`, '%Y-%m-%d') sale_date,SUM(orditem.`num`) sale_num, prd.`type`,`prd`.`desc` FROM `ord` INNER JOIN orditem ON `ord`.`id` = orditem.`ord_id` INNER JOIN prd ON orditem.`prd_id` = prd.`id` WHERE `ord`.`date` > DATE_SUB(CURDATE(), INTERVAL 1 WEEK) GROUP BY sale_date,prd.`type` ORDER BY sale_date DESC;table
<configuration>
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>cli
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
</configuration>
date
HADOOP_HOME=/opt/hadoop
49
50 # Hive Configuration Directory can be controlled by:
51 export HIVE_CONF_DIR=/opt/hive/conf
im