select x1.login_date,concat(round((x1.T1_retention/x1.T1_retention_last-1)*100,2),'%') as t1_retention_rate from (
select x.login_date,x.T1_retention,lag(x.T1_retention) over(order by x.login_date) as T1_retention_last from (
select cast(t.login_time as date) as login_date,count(distinct t.usr_id) as T1_retention from user_login_log t
where cast(t.login_time as date) between date_sub(current_date(),interval 31 day) and current_date()
group by cast(t.login_time as date)
)x
)x1
where x1.T1_retention_last is not null
;
SELECT X.Y
,MAX(CASE WHEN X.CITY='beijing' THEN X.TMPEND) AS 北京
,MAX(CASE WHEN X.CITY='shanghai' THEN X.TMP END) AS 上海
,MAX(CASE WHEN X.CITY='shenzhen' THEN X.TMP END) AS 深圳
,MAX(CASE WHEN X.CITY='guangzhou' THEN X.TMP END) AS广州
from(
SELECT t.cityAS CITY,
YEAR(t.dt) AS Y,
CAST(ROUND(AVG(t.tmp_h), 2) AS DECIMAL(10,2)) AS TMP
FROM weather_rcd_china t
WHERE cast(t.dt as date) BETWEEN '2011-01-01' AND '2022-12-31'
GROUP BY t.city, YEAR(t.dt)
) X
GROUP BY X.Y
order by X.Y ;
SELECT X.Y
,MAX(CASE WHEN X.CITY='beijing' THEN CAST(X.TMP AS DECIMAL(10,2)) END) AS 北京
,MAX(CASE WHEN X.CITY='shanghai' THEN CAST(X.TMP AS DECIMAL(10,2)) END) AS 上海
,MAX(CASE WHEN X.CITY='shenzhen' THEN CAST(X.TMP AS DECIMAL(10,2)) END) AS 深圳
,MAX(CASE WHEN X.CITY='guangzhou' THEN CAST(X.TMP AS DECIMAL(10,2)) END) AS广州
from(
SELECT t.cityAS CITY,
YEAR(t.dt) AS Y,
round(AVG(t.tmp_h),2) AS TMP
FROM weather_rcd_china t
WHERE cast(t.dt as date) BETWEEN '2011-01-01' AND '2022-12-31'
GROUP BY t.city, YEAR(t.dt)
) X
GROUP BY X.Y
order by X.Y ;
SELECT X.Y
,MAX(CASE WHEN X.CITY='beijing' THEN CAST(X.TMP AS DECIMAL(10,2)) END) AS 北京
,MAX(CASE WHEN X.CITY='shanghai' THEN CAST(X.TMP AS DECIMAL(10,2)) END) AS 上海
,MAX(CASE WHEN X.CITY='shenzhen' THEN CAST(X.TMP AS DECIMAL(10,2)) END) AS 深圳
,MAX(CASE WHEN X.CITY='guangzhou' THEN CAST(X.TMP AS DECIMAL(10,2)) END) AS广州
from(
SELECT t.cityAS CITY,
YEAR(t.dt) AS Y,
round(AVG(t.tmp_h),2) AS TMP
FROM weather_rcd_china t
WHERE t.dt BETWEEN '2011-01-01' AND '2022-12-31'
GROUP BY t.city, YEAR(t.dt)
) X
GROUP BY X.Y
order by X.Y ;
SELECT X.Y
,MAX(CASE WHEN X.CITY='beijing' THEN X.TMP END) AS 北京
,MAX(CASE WHEN X.CITY='shanghai' THEN X.TMP END) AS 上海
,MAX(CASE WHEN X.CITY='shenzhen' THEN X.TMP END) AS 深圳
,MAX(CASE WHEN X.CITY='guangzhou' THEN X.TMP END) AS广州
from(
SELECT t.cityAS CITY,
YEAR(t.dt) AS Y,
round(AVG(t.tmp_h),2) AS TMP
FROM weather_rcd_china t
WHERE t.dt BETWEEN '2011-01-01' AND '2022-12-31'
GROUP BY t.city, YEAR(t.dt)
) X
GROUP BY X.Y
order by X.Y ;
SELECT X.Y
,MAX(CASE WHEN X.CITY='beijing' THEN X.TMP END) AS 北京
,MAX(CASE WHEN X.CITY='chengdu' THEN X.TMP END) AS 上海
,MAX(CASE WHEN X.CITY='shenzhen' THEN X.TMP END) AS 深圳
,MAX(CASE WHEN X.CITY='guangzhou' THEN X.TMP END) AS广州
from(
SELECT t.cityAS CITY,
YEAR(t.dt) AS Y,
round(AVG(t.tmp_h),2) AS TMP
FROM weather_rcd_china t
WHERE t.dt BETWEEN '2011-01-01' AND '2022-12-31'
GROUP BY t.city, YEAR(t.dt)
) X
GROUP BY X.Y
order by X.Y ;
SELECT X.Y
,MAX(CASE WHEN X.CITY='beijing' THEN X.TMP END) AS 北京
,MAX(CASE WHEN X.CITY='chengdu' THEN X.TMP END) AS 成都
,MAX(CASE WHEN X.CITY='shenzhen' THEN X.TMP END) AS 深圳
,MAX(CASE WHEN X.CITY='changsha' THEN X.TMP END) AS长沙
,MAX(CASE WHEN X.CITY='kunming' THEN X.TMP END) AS 昆明
from(
SELECT t.cityAS CITY,
YEAR(t.dt) AS Y,
round(AVG(t.tmp_h),2) AS TMP
FROM weather_rcd_china t
WHERE t.dt BETWEEN '2011-01-01' AND '2022-12-31'
GROUP BY t.city, YEAR(t.dt)
) X
GROUP BY X.Y
order by X.Y ;
SELECT X.Y
,MAX(CASE WHEN X.CITY='beijing' THEN X.TMP END) AS 北京
,MAX(CASE WHEN X.CITY='chengdu' THEN X.TMP END) AS 成都
,MAX(CASE WHEN X.CITY='shenzhen' THEN X.TMP END) AS 深圳
,MAX(CASE WHEN X.CITY='changsha' THEN X.TMP END) AS长沙
,MAX(CASE WHEN X.CITY='kunming' THEN X.TMP END) AS昆明
from(
SELECT t.cityAS CITY,
YEAR(t.dt) AS Y,
round(AVG(t.tmp_h),2) AS TMP
FROM weather_rcd_china t
WHERE t.dt BETWEEN '2011-01-01' AND '2022-12-31'
GROUP BY t.city, YEAR(t.dt)
) X
GROUP BY X.Y
order by X.Y ;
SELECT X.Y
,CASE WHEN X.CITY='北京' THEN X.TMP END AS 北京
,CASE WHEN X.CITY='成都' THEN X.TMP END AS 成都
,CASE WHEN X.CITY='深圳' THEN X.TMP END AS 深圳
,CASE WHEN X.CITY='长沙' THEN X.TMP END AS 长沙
,CASE WHEN X.CITY='昆明' THEN X.TMP END AS 昆明
from(
SELECT case when t.city='beijing' THEN '北京'
when t.city='chengdu' THEN '成都'
when t.city='changsha' THEN '长沙'
when t.city='kunming' THEN '昆明'
when t.city='shenzhen' THEN '深圳'
ELSE t.city END AS CITY,
YEAR(t.dt) AS Y,
round(AVG(t.tmp_h),2) AS TMP
FROM weather_rcd_china t
WHERE t.dt BETWEEN '2011-01-01' AND '2022-12-31'
GROUP BY t.city, YEAR(t.dt)
) X
order by X.Y ;