当前位置:网站首页>Show the actual work case of creating intermediate data table with SQL
Show the actual work case of creating intermediate data table with SQL
2022-06-28 19:01:00 【South Lake Fishing Song】
show databases;
show tables;
select * from bi_df_m bdm ;
# Chain ratio
# consumption
select
-- substr(a.d,1,7) as month ,
STR_TO_DATE(a.d,'%Y-%m-%d') as month ,
round(a.consume) as consumption ,
-- b.dd,
-- b.original_month,
round(b.consume) as Month on month , -- as consume_last,
round((a.consume-b.consume)/b.consume,2) as Link ratio -- month_rate
from
(
select DATE_FORMAT(CONCAT(r_year,'-',r_month,'-01'),'%Y-%m-%d') as d,consume
from
(
select r_year,r_month,sum(consume) as consume
from grafana_bi.bi_df_m bdm
-- where channel_kind = 'APP' AND brand_name = '2_bibgold'
group by r_year,r_month) t
) a
left join
(
-- Run right
select DATE_ADD(DATE_FORMAT(CONCAT(r_year,'-',r_month,'-01'),'%Y-%m-%d'),INTERVAL 1 month ) as dd
,DATE_FORMAT(CONCAT(r_year,'-',r_month,'-01'),'%Y-%m-%d') as original_month
,consume
from
(
select r_year,r_month,sum(consume) as consume
from grafana_bi.bi_df_m bdm
-- where channel_kind = 'APP' AND brand_name = '2_bibgold'
group by r_year,r_month) t
) b
on a.d = b.dd;
# register
select
-- substr(a.d,1,7) as month ,
STR_TO_DATE(a.d,'%Y-%m-%d') as time,
round(a.reg) as Number of registrations ,
-- b.dd,
-- b.original_month,
round(b.reg) as Month on month , -- as reg_last,
round((a.reg-b.reg)/b.reg,2) as Month on month growth rate -- month_rate
from
(
select DATE_FORMAT(CONCAT(r_year,'-',r_month,'-01'),'%Y-%m-%d') as d,reg
from
(
select r_year,r_month,sum(reg) as reg
from grafana_bi.bi_df_m bdm
-- where channel_kind = 'APP' AND brand_name = '2_bibgold'
group by r_year,r_month) t
) a
left join
(
-- Run right
select DATE_ADD(DATE_FORMAT(CONCAT(r_year,'-',r_month,'-01'),'%Y-%m-%d'),INTERVAL 1 month ) as dd
,DATE_FORMAT(CONCAT(r_year,'-',r_month,'-01'),'%Y-%m-%d') as original_month
,reg
from
(
select r_year,r_month,sum(reg) as reg
from grafana_bi.bi_df_m bdm
-- where channel_kind = 'APP' AND brand_name = '2_bibgold'
group by r_year,r_month) t
) b
on a.d = b.dd;
# --------------------------------------- adopt r_year,r_month, Build a new field ' year - month -01' ----------------------------------
desc grafana_bi.bi_df_m ; # Look at the data table fields :
use grafana_bi;
DROP TABLE IF EXISTS `temp_bi_df_m`;
CREATE TABLE IF NOT EXISTS `temp_bi_df_m`(
`r_year` int(10)
,`r_month` varchar(10)
,`channel_kind` varchar(10)
,`brand_name` varchar(10)
,`consume` int(10)
,`flow` int(10)
,`ent` int(10)
,`reg` int(10)
,`r_quarter` varchar(10)
,`ym` varchar(10) # New fields
,`update_Time` varchar(50)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
# Check whether the data table was created successfully
SELECT * from grafana_bi.temp_bi_df_m limit 10;
# Interpolation number
insert into grafana_bi.temp_bi_df_m(r_year,r_month,channel_kind,brand_name,consume,flow,ent,reg,r_quarter,ym,update_Time)
select
r_year
,r_month
,channel_kind
,brand_name
,consume
,flow
,ent
,reg
,r_quarter
,DATE_FORMAT(CONCAT(r_year,'-',r_month,'-01'),'%Y-%m-%d') as ym # Added one rm Field
,update_Time
from grafana_bi.bi_df_m ;
show tables;
# Adding fields and creating a new table succeeded :
select *
from grafana_bi.temp_bi_df_m ;
# -------------------------------------- In the new bottom table temp_bi_df_m In the development grafana sql Script --------------------------------------
-- consumption
select
STR_TO_DATE(a.d,'%Y-%m-%d') as time,
a.consume as consume ,
b.consume as consume_last,
round((a.consume-b.consume)/b.consume,2) as month_rate
from
(
select ym as d,consume
from (select ym,sum(consume) as consume -- According to :r_year,r_month grouping Become installation ym Field grouping
from temp_bi_df_m tb
where channel_kind = 'APP' AND brand_name = '2_bibgold'
group by ym) t ) a
left join
(
-- Run right
select DATE_ADD(ym,INTERVAL 1 month ) as dd
,ym as original_month
,consume
from
(
select ym,sum(consume) as consume
from temp_bi_df_m tb
where channel_kind = 'APP' AND brand_name = '2_bibgold'
group by ym) t
) b
on a.d = b.dd;
-- register
select
STR_TO_DATE(a.d,'%Y-%m-%d') as time,
a.reg as reg ,
b.reg as reg_last,
round((a.reg-b.reg)/b.reg,2) as month_rate
from
(
select ym as d,reg
from (select ym,sum(reg) as reg -- According to :r_year,r_month grouping Become installation ym Field grouping
from temp_bi_df_m tb
where channel_kind = 'APP' AND brand_name = '2_bibgold'
-- where channel_kind in ($channel_kind) AND brand_name in ($brand_name)
group by ym) t ) a
left join
(
-- Run right
select DATE_ADD(ym,INTERVAL 1 month ) as dd
,ym as original_month
,reg
from
(
select ym,sum(reg) as reg
from temp_bi_df_m tb
where channel_kind = 'APP' AND brand_name = '2_bibgold'
-- where channel_kind in ($channel_kind) AND brand_name in ($brand_name)
group by ym) t
) b
on a.d = b.dd;
-- Into gold :
select
STR_TO_DATE(a.d,'%Y-%m-%d') as time,
a.ent as ent ,
b.ent as ent_last,
round((a.ent-b.ent)/b.ent,2) as month_rate
from
(
select ym as d,ent
from (select ym,sum(ent) as ent -- According to :r_year,r_month grouping Become installation ym Field grouping
from temp_bi_df_m tb
-- where channel_kind = 'APP' AND brand_name = '2_bibgold'
where channel_kind in ($channel_kind) AND brand_name in ($brand_name)
group by ym) t ) a
left join
(
-- Run right
select DATE_ADD(ym,INTERVAL 1 month ) as dd
,ym as original_month
,ent
from
(
select ym,sum(ent) as ent
from temp_bi_df_m tb
-- where channel_kind = 'APP' AND brand_name = '2_bibgold'
where channel_kind in ($channel_kind) AND brand_name in ($brand_name)
group by ym) t
) b
on a.d = b.dd;
#--------------------------------------------------- Development adapts to grafana Analysis chart of sql sentence --------------------------------------
use grafana_bi;
DROP TABLE IF EXISTS `app_c_df_m`;
CREATE TABLE IF NOT EXISTS `app_c_df_m`(
`ddate` varchar(50)
,`consume` int(10)
,`consume2` int(10)
-- ,`month_rate` decimal(10,3)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
select *
from app_c_df_m;
# Interpolation number
insert into grafana_bi.app_c_df_m(ddate,consume,consume2)
select
a.d as ddate,
a.consume as consume ,
b.consume as consume_last
-- round((a.consume-b.consume)/b.consume,2) as month_rate
from
(
select ym as d,consume
from (select ym,sum(consume) as consume -- According to :r_year,r_month grouping Become installation ym Field grouping
from temp_bi_df_m tb
where channel_kind = 'APP' AND brand_name = '2_bibgold'
group by ym) t ) a
left join
(
-- Run right
select DATE_ADD(ym,INTERVAL 1 month ) as dd
,ym as original_month
,consume
from
(
select ym,sum(consume) as consume
from temp_bi_df_m tb
where channel_kind = 'APP' AND brand_name = '2_bibgold'
group by ym) t
) b
on a.d = b.dd;
SELECT * from grafana_bi.app_c_df_m;
# grafana sql Script :
-- Law 1 : Individual query To write :
select STR_TO_DATE(ddate,'%Y-%m-%d') as time
,consume
,consume2
from grafana_bi.app_c_df_m;
-- Law two : In two query To write :
select STR_TO_DATE(ddate,'%Y-%m-%d') as time
,consume
from grafana_bi.app_c_df_m;
select STR_TO_DATE(ddate,'%Y-%m-%d') as time
,consume2
from grafana_bi.app_c_df_m;
边栏推荐
猜你喜欢

用户网络模型与QoE

Mindspire series one loading image classification data set

牛津大學教授Michael Wooldridge:AI社區近40年如何看待神經網絡

Anonymous function this pointing and variable promotion

Advanced technology management - how managers communicate performance and control risks

Render function parsing

从知名软件提取出的神器,吊打一众付费

tensorboard 使用总结

About Covariance and Correlation(协方差和相关)

rancher增加/删除node节点
随机推荐
grafana绘制走势图
CVPR2022 | 浙大、蚂蚁集团提出基于标签关系树的层级残差多粒度分类网络,建模多粒度标签间的层级知识
Cvpr2022 | Zhejiang University and ant group put forward a hierarchical residual multi granularity classification network based on label relation tree to model hierarchical knowledge among multi granu
上传文件列表(文件名重复加括号标识)
OOM out of memory 内存溢出
idea其他分支合并到dev分支
使用Karmada实现Helm应用的跨集群部署
【Unity3D】发射(RayCast)物理射线(Ray)
怎样去除DataFrame字段列名
几行代码就能实现复杂的 Excel 导入导出,这个工具类真心强大!
Collection of real test questions
use. NETCORE's own background job, which simply simulates producers and consumers' processing of request response data in and out of the queue
深入解析kubernetes中的选举机制
Alist+RaiDrive 给电脑整个80亿GB硬盘
OpenHarmony—内核对象事件之源码详解
Sound network releases lingfalcon Internet of things cloud platform, which can build sample scenarios in one hour
async-validator.js数据校验器
Some error prone points of C language pointer
内存抖动
postgresql数据库docker