0
我堆放在以下查詢上。我需要創建一個if語句或類似的東西來區分哪些「CASE」應該添加到我的選擇查詢中。如果聲明區分哪個「Case」查詢應該添加到選擇查詢
If page_type = 'Region' or 'City'
這添加到查詢:
(CASE When landing_page like concat('%',path_id,'%') and
(LENGTH(landing_page) - LENGTH(REPLACE(landing_page, '/' ,''))/LENGTH('/')) = 2
Then 'True' Else 'False' End as 'correct lp' ,)
Elseif page_type = 'Item'
這添加到查詢:
(CASE When landing_page like concat('%',path_id,'%') and
(LENGTH(landing_page) - LENGTH(REPLACE(landing_page, '/' ,''))/LENGTH('/')) = 3
Then 'True' Else 'False' End as 'correct lp' ,)
Elseif page_type = 'POI (Alle)'
這添加到查詢:
(CASE When landing_page like concat('%',path_id,'%') and
(LENGTH(landing_page) - LENGTH(REPLACE(landing_page, '/' ,''))/LENGTH('/')) = 3 and
'Hotel' NOT IN landing_page
Then 'True' Else 'False' End as 'correct lp' ,)
個案例查詢應根據if
結果被添加到下面的查詢:
SELECT
MONTHNAME(k.crawl_date) As 'Month',
YEAR(k.crawl_date) As 'Year',
WEEKOFYEAR(k.crawl_date) As 'Week',
k.landing_page,
k.pos,
CASE WHEN k.pos = 0 THEN 'No Rank' WHEN k.pos < 4 THEN 'Top 3' WHEN k.pos < 11 THEN 'Page 1'
WHEN k.pos < 21 THEN 'Page 2' WHEN k.pos < 31 THEN 'Page 3' WHEN k.pos < 41 THEN 'Page 4'
WHEN k.pos < 51 THEN 'Page 5' WHEN k.pos < 61 THEN 'Page 6' WHEN k.pos < 71 THEN 'Page 7'
WHEN k.pos < 81 THEN 'Page 8' WHEN k.pos < 91 THEN 'Page 9' WHEN k.pos < 101 THEN 'Page 10'
WHEN k.pos < 111 THEN 'Page 11' END as 'Page',
k.path_id,
k.domain,
x.keyword,
x.engine_id,
l.bucket,
l.page_type,
l.item_label
FROM
xovi_stats k
LEFT JOIN xovi_keywords x ON k.keyword_id = x.id
LEFT JOIN xovi_labels l ON l.id = x.label_id
「CASE」子句將被添加到「SELECT」部分中,我想呢? – RandomSeed
是的,這是正確的。 – CompFreak