MySQL_时间段维度统计
来源:互联网 发布:淘宝手机优惠券 编辑:程序博客网 时间:2024/05/29 16:52
MySQL#时间维度统计
场景
给定某一时间段对这段时间内每一天的数据做聚合统计。
解决
1.构造精确到天的时间区间(取任意行数大于31的表,通过子查询和自定义变量即可构造特定日期行数)
2.业务数据统计
3.依据时间维度join
示例
set @i := -1;selectg1.date_str, ifnull(g2.q_ct,0) q_ct, ifnull(g3.sku_final_price_cny, 0) sku_final_price_cny, ifnull(g3.sku_list_price_cny, 0) sku_list_price_cny, ifnull(g3.shopping_quantity, 0) shopping_quantityfrom (select date(date_add(str_to_date('2014-11-01', '%Y-%m-%d'), interval @i:=@i + 1 day)) as date_str from (select 1 from t_account b limit 1 , 30) b) g1left join (SELECT date(a.goods_ctime) q_time, count(1) q_ct FROM t_goods a where 1 = 1 and a.goods_ctime >= '2014-01-01' and a.goods_ctime < '2015-01-01' group by date(a.goods_ctime)) g2 ON g2.q_time = g1.date_strleft join (select date(b.order_ctime) ctime, sum(c.shopping_quantity * c.sku_final_price_cny) sku_final_price_cny, sum(c.shopping_quantity * c.sku_list_price_cny) sku_list_price_cny, sum(c.shopping_quantity) shopping_quantity from t_order b left join t_order_item c ON c.order_id = b.order_id where b.order_state > 0 and b.order_status >= 2 and b.order_ctime >= '2014-01-01 00:00:00' and b.order_ctime < '2015-01-01 00:00:00' group by date(b.order_ctime)) g3 ON g3.ctime = g1.date_strorder by g1.date_str;set @i := -1;
效果
0 0
- MySQL_时间段维度统计
- oracle间隔时间段统计
- DataView.RowFilter 时间段统计
- excel时间段统计问题
- 时间段 分组 统计
- 多个时间段统计
- mysql 根据时间段统计
- 任意时间段量的统计
- 按天、周、月、自定义时间段统计
- 锋利的SQL:时间段天数统计
- (SQL语句)按指定时间段分组统计
- mysql按照时间段内 每天统计
- 统计某一时间段内的数据
- 统计两表时间段重复部分
- javabean+Jsp统计网站时间段访问数
- MySQL统计函数记录——时间段统计
- MySQL统计函数记录——时间段统计
- linux脚本统计,日志查询相关,统计时间段日志
- 民生信托-联华星河IEO经营性物业抵押贷款集合资金信托计划
- 在ubuntu下安装libpcap库 (解决方案很全)
- 由大学到至今的小作品(不定时更新)
- innodb的锁
- 杭电1004题
- MySQL_时间段维度统计
- 获得屏幕状态栏高度
- kmeans聚类练习
- 渤海信托·金鑫利粮储贷款项目集合资金信托计划
- gcc编译出现”undefined reference to `pcap_parse’”
- QUnit使用入门
- 方正东亚•遵义道桥流动资金贷款集合资金信托计划
- Android提供的LruCache类简介
- 最喜欢此等大杀器