# hhh流量週報的SQL cmd
# 本週關鍵字點擊成長
# 不太懂為什麼要一直洗掉。

-- select
-- 	weeknum, id
-- from 
-- 	hhh.hhh_weekly_keywords

# 先找尋不同週的兩個table
-- select *  from hhh.hhh_weekly_keywords where weeknum=26;
select 
	A.query, A.clicks, A.ctr, A.impressions, A.weeknum, 
    B.weeknum, B.clicks, B.ctr, B.impressions,
    ((A.clicks-B.clicks) / B.clicks)*100 as clicks_growth
from
	((select query, clicks, ctr, impressions, weeknum 
	from hhh.hhh_weekly_keywords 
	where weeknum=26) as A
	inner join (select query, clicks, ctr, impressions, weeknum from hhh.hhh_weekly_keywords  where weeknum=25) as B
	on A.query=B.query)
order by 
	clicks_growth desc
limit 20;