



DROP TABLE raena_analytics.raw_ingredient_split_name;
CREATE TABLE raena_analytics.raw_ingredient_split_name AS
SELECT * ,
       split_part(concern,', ',1) concern1,
       split_part(concern,', ',2) concern2,
       split_part(concern,', ',3) concern3,
       split_part(concern,', ',4) concern4,
       split_part(concern,', ',5) concern5,
       split_part(top_marketing_ingredients ,', ',1) ingredient1,
       split_part(top_marketing_ingredients,', ',2) ingredient2,
       split_part(top_marketing_ingredients,', ',3) ingredient3,
       split_part(top_marketing_ingredients,', ',4) ingredient4,
       split_part(top_marketing_ingredients,', ',5) ingredient5,
       split_part(top_marketing_ingredients,', ',6) ingredient6,
       split_part(top_marketing_ingredients,', ',7) ingredient7,
       split_part(top_marketing_ingredients,', ',8) ingredient8,
       split_part(top_marketing_ingredients,', ',9) ingredient9,
       split_part(top_marketing_ingredients,', ',10) ingredient10,
       split_part(top_marketing_ingredients,', ',11) ingredient11
FROM
  (SELECT DISTINCT group_base,
                   sku ,
                   lower(concern) concern,
                   lower(top_marketing_ingredients) top_marketing_ingredients,
                   CASE
                       WHEN concern=''
                            AND top_marketing_ingredients='' THEN 1
                   END flag
   FROM raena_analytics.ingredients_base_table_final) A
WHERE flag IS NULL;

  DROP TABLE raena_analytics.raw_ingredient_mapping_table_stage;


CREATE TABLE raena_analytics.raw_ingredient_mapping_table_stage AS
SELECT A.* ,
       B.group_base mapping_group_base,
       B.concern mapping_concerns,
       B.top_marketing_ingredients mapping_ingredients
FROM raena_analytics.raw_ingredient_split_name A
LEFT JOIN
  (SELECT *
   FROM raena_analytics.raw_ingredient_split_name) B ON 1=1; 

DROP TABLE if exists  raena_analytics.raw_ingredient_mapping_table_stage2;

CREATE TABLE raena_analytics.raw_ingredient_mapping_table_stage2 AS
SELECT * ,
       CASE
           WHEN raena_analytics.udf_string_campare(concern1,mapping_concerns) <>''
                AND raena_analytics.udf_string_campare(concern1,mapping_concerns) <> 'NA'
                AND mapping_concerns IS NOT NULL THEN 1
           ELSE 0
       END flag_concern1,
       CASE
           WHEN raena_analytics.udf_string_campare(concern2,mapping_concerns) <>''
                AND raena_analytics.udf_string_campare(concern2,mapping_concerns) <>'NA'
                AND mapping_concerns IS NOT NULL THEN 1
           ELSE 0
       END flag_concern2,
       CASE
           WHEN raena_analytics.udf_string_campare(concern3,mapping_concerns) <>''
                AND raena_analytics.udf_string_campare(concern3,mapping_concerns) <>'NA'
                AND mapping_concerns IS NOT NULL THEN 1
           ELSE 0
       END flag_concern3,
       CASE
           WHEN raena_analytics.udf_string_campare(concern4,mapping_concerns) <>''
                AND raena_analytics.udf_string_campare(concern4,mapping_concerns) <>'NA'
                AND mapping_concerns IS NOT NULL THEN 1
           ELSE 0
       END flag_concern4,
       CASE
           WHEN raena_analytics.udf_string_campare(concern5,mapping_concerns) <>''
                AND raena_analytics.udf_string_campare(concern5,mapping_concerns) <>'NA'
                AND mapping_concerns IS NOT NULL THEN 1
           ELSE 0
       END flag_concern5,
       REGEXP_COUNT(concern ,', ')+1 total_count_concern,
       CASE
           WHEN raena_analytics.udf_string_campare(ingredient1,mapping_ingredients) <>''
                AND raena_analytics.udf_string_campare(ingredient1,mapping_ingredients) <>'NA'
                AND mapping_ingredients IS NOT NULL THEN 1
           ELSE 0
       END flag_ingredient1,
       CASE
           WHEN raena_analytics.udf_string_campare(ingredient2,mapping_ingredients) <>''
                AND raena_analytics.udf_string_campare(ingredient2,mapping_ingredients) <>'NA'
                AND mapping_ingredients IS NOT NULL THEN 1
           ELSE 0
       END flag_ingredient2,
       CASE
           WHEN raena_analytics.udf_string_campare(ingredient3,mapping_ingredients) <>''
                AND raena_analytics.udf_string_campare(ingredient3,mapping_ingredients) <>'NA'
                AND mapping_ingredients IS NOT NULL THEN 1
           ELSE 0
       END flag_ingredient3,
       CASE
           WHEN raena_analytics.udf_string_campare(ingredient4,mapping_ingredients) <>''
                AND raena_analytics.udf_string_campare(ingredient4,mapping_ingredients) <>'NA'
                AND mapping_ingredients IS NOT NULL THEN 1
           ELSE 0
       END flag_ingredient4,
       CASE
           WHEN raena_analytics.udf_string_campare(ingredient5,mapping_ingredients) <>''
                AND raena_analytics.udf_string_campare(ingredient5,mapping_ingredients) <>'NA'
                AND mapping_ingredients IS NOT NULL THEN 1
           ELSE 0
       END flag_ingredient5,
       CASE
           WHEN raena_analytics.udf_string_campare(ingredient6,mapping_ingredients) <>''
                AND raena_analytics.udf_string_campare(ingredient6,mapping_ingredients) <>'NA'
                AND mapping_ingredients IS NOT NULL THEN 1
           ELSE 0
       END flag_ingredient6,
       CASE
           WHEN raena_analytics.udf_string_campare(ingredient7,mapping_ingredients) <>''
                AND raena_analytics.udf_string_campare(ingredient7,mapping_ingredients) <>'NA'
                AND mapping_ingredients IS NOT NULL THEN 1
           ELSE 0
       END flag_ingredient7,
       CASE
           WHEN raena_analytics.udf_string_campare(ingredient8,mapping_ingredients) <>''
                AND raena_analytics.udf_string_campare(ingredient8,mapping_ingredients) <>'NA'
                AND mapping_ingredients IS NOT NULL THEN 1
           ELSE 0
       END flag_ingredient8,
       CASE
           WHEN raena_analytics.udf_string_campare(ingredient9,mapping_ingredients) <>''
                AND raena_analytics.udf_string_campare(ingredient9,mapping_ingredients) <>'NA'
                AND mapping_ingredients IS NOT NULL THEN 1
           ELSE 0
       END flag_ingredient9,
       CASE
           WHEN raena_analytics.udf_string_campare(ingredient10,mapping_ingredients) <>''
                AND raena_analytics.udf_string_campare(ingredient10,mapping_ingredients) <>'NA'
                AND mapping_ingredients IS NOT NULL THEN 1
           ELSE 0
       END flag_ingredient10,
       CASE
           WHEN raena_analytics.udf_string_campare(ingredient11,mapping_ingredients) <>''
                AND raena_analytics.udf_string_campare(ingredient11,mapping_ingredients) <>'NA'
                AND mapping_ingredients IS NOT NULL THEN 1
           ELSE 0
       END flag_ingredient11,
       REGEXP_COUNT(top_marketing_ingredients ,', ')+1  total_count_ingredient
FROM raena_analytics.raw_ingredient_mapping_table_stage
WHERE group_base <> mapping_group_base;

  DROP TABLE if exists raena_analytics.raw_ingredient_mapping_table_stage3;


CREATE TABLE raena_analytics.raw_ingredient_mapping_table_stage3 AS
SELECT *,
       flag_concern1+flag_concern2+flag_concern3+flag_concern3+flag_concern3 total_concern_match,
       flag_ingredient1+flag_ingredient2+flag_ingredient3+flag_ingredient4+flag_ingredient5+flag_ingredient6+flag_ingredient7+flag_ingredient8+flag_ingredient9+flag_ingredient10+flag_ingredient11 total_ingredient_match
FROM raena_analytics.raw_ingredient_mapping_table_stage2 ;


DROP TABLE IF EXISTS raena_analytics.raw_ingredient_mapping_table_stage4;


CREATE TABLE raena_analytics.raw_ingredient_mapping_table_stage4 AS
SELECT *, (total_concern_match*100/total_count_concern) Percent_concern_match, (total_ingredient_match*100/total_count_ingredient) Percent_ingredient_match ,
       CASE WHEN concern='' AND (total_ingredient_match*100/total_count_ingredient)>0 THEN 1
             WHEN (total_concern_match*100/total_count_concern)>0 AND top_marketing_ingredients='' THEN 1
             WHEN (total_concern_match*100/total_count_concern)>0 AND (total_ingredient_match*100/total_count_ingredient)>0 THEN 1
       END percent_flag
FROM raena_analytics.raw_ingredient_mapping_table_stage3;


Drop table if exists raena_analytics.raw_ingredient_mapping_table;

Create table raena_analytics.raw_ingredient_mapping_table
as
SELECT group_base,
       sku,
       concern,
       top_marketing_ingredients,
       mapping_group_base,
       mapping_concerns,
       mapping_ingredients,
       percent_concern_match,
       Percent_ingredient_match
FROM raena_analytics.raw_ingredient_mapping_table_stage4
WHERE percent_flag=1
ORDER BY group_base ,
         percent_concern_match DESC ,
         Percent_ingredient_match DESC;


DROP TABLE IF EXISTS raena_analytics.sku_in_stock;


CREATE TABLE raena_analytics.sku_in_stock AS
SELECT sku ,
       sum(coalesce(F.stock_limit,0)) in_stock
FROM raena_catalog_management.product C
LEFT JOIN raena_catalog_management.product_inventory F ON C.id = F.product_id
GROUP BY sku; 

 --------------------------------------------------------------task 1 ----------------

drop table if exists raena_analytics.recommendation_power_seller_base_alt;

create table raena_analytics.recommendation_power_seller_base_alt
as
select distinct email from raena_analytics.om_acquisition_mapping_list
union select distinct "email id" from raena_analytics.AM_REVENUE_LEAKAGE_LIST  ;


INSERT INTO raena_analytics.recommendation_power_seller_base_alt
             values ('cindyvioleta29@yahoo.com'),
('sherryfannydesita@gmail.com'),
('masintansilalahi@yahoo.co.id'),
('rumahskincarebpp@gmail.com'),
('puturisca@gmail.com'),
('sieny.go@gmail.com'),
('oki.zhang1988@gmail.com'),
('jeremytantono@yahoo.co.id'),
('yuke.cipta@gmail.com'),
('kwonvic@hotmail.com'),
('ervinafransiska95@gmail.com'),
('indahamaliasasmita@gmail.com'),
('mirosebeauty@gmail.com'),
('fourrshoptarakan@gmail.com'),
('stuffbyms@gmail.com'),
('cindyrissa14@gmail.com'),
('lieke1212@gmail.com'),
('jelitacosmetic.yk@gmail.com'),
('metafuji@gmail.com'),
('destiyapradhani@gmail.com'),
('liepinghau@gmail.com'),
('jennifer_kambuno@yahoo.com'),
('y35beauty@gmail.com'),
('nisamulya@gmail.com'),
('issadella@yahoo.co.id'),
('hartono.henny@yahoo.co.id'),
('a2335572@gmail.com'),
('navisgusmiati24@gmail.com'),
('djiwandimelany@gmail.com'),
('colinakoh178@gmail.com'),
('fairybeaute17@gmail.com'),
('fajri.vanbio95@gmail.com'),
('zidney_yao@yahoo.com'),
('chandraalex305@gmail.com'),
('elly.elisha@gmail.com'),
('erlinapr13@gmail.com'),
('mechan_06@hotmail.com'),
('limvincents@hotmail.com'),
('tjuganteng@gmail.com'),
('sralaydrus96@yahoo.com'),
('duwik_tonx@yahoo.co.id'),
('adelshopadelia@gmail.com'),
('shierlysusanto2405@gmail.com'),
('murni.cosmetics55@gmail.com'),
('stg_purchasing_melisa@yahoo.com'),
('asri.nilasari@watsons.co.id'),
('wayanndiana@gmail.com'),
('emailtedy@gmail.com'),
('Shantifm@hotmail.com'),
('shintachristiani2911@gmail.com'),
('dotienigloo@gmail.com'),
('mirandadessy95@gmail.com'),
('pangeranpetirr@gmail.com'),
('mariamellysacandra@ymail.com'),
('evitamalaa@ymail.com'),
('lindadarwinp@gmail.com'),
('dyfabandung@gmail.com'),
('yestastore@gmail.com'),
('outletmadanibeauty@gmail.com'),
('mrs.kumara@yahoo.com'),
('cindylum23@gmail.com'),
('fairy_love90@ymail.com'),
('fajarcosmetikpekanbaru@gmail.com'),
('alapstorekosmetik@gmail.com'),
('marlinabahnur@yahoo.co.id'),
('miswarderi61@gmail.com'),
('kristian_tjia@yahoo.co.id'),
('dessi.three@gmail.com'),
('rumahkurumahta@gmail.com'),
('nabilaalifia2000@gmail.com'),
('ullyfina@gmail.com'),
('tjindaidyandy@gmail.com'),
('shintayuu@gmail.com'),
('ratihpuji001@gmail.com'),
('shynobyshould@gmail.com'),
('rismawatisapu101@gmail.com'),
('caramelmadeby@gmail.com'),
('piyamapoppy@gmail.com'),
('scarlettwhitening.manado@gmail.com'),
('makeupbliss.id@gmail.com'),
('agnyjmpardosi@gmail.com'),
('sherbeautee@gmail.com'),
('yfbeauty99@gmail.com'),
('cmstadulako36@gmail.com'),
('lizalgs97@gmail.com'),
('emailnyawabisabi@gmail.com'),
('alvhiraalamrih@gmail.com'),
('megasyaf10@gmail.com'),
('ismisarisapitri6@gmail.com'),
('realrima91@gmail.com'),
('hestynorata74@gmail.com'),
('tokopinkbox@gmail.com'),
('melly.angelica@sils.co.id'),
('baguzokee@gmail.com'),
('vandy_hood@yahoo.com'),
('stevenwerencius15@gmail.com'),
('qurniaulan123@gmail.com'),
('ivanalystia21@gmail.com'),
('claralverinas@gmail.com'),
('riaarddd@gmail.com'),
('yayz_bubble@yahoo.com'),
('elsa.rivani@rocketmail.com'),
('feyrenpusura@gmail.com'),
('gunz_r@yahoo.com'),
('asrularman077@gmail.com'),
('hellojuwitaang@gmail.com'),
('bernike.daniel@gmail.com'),
('ayuerawati1993@gmail.com'),
('sudutcantik03@gmail.com'),
('norio.agnes@gmail.com'),
('smarch2u@gmail.com'),
('nunungokta8@gmail.com'),
('siaocie.tw@gmail.com'),
('sandrachen20@icloud.com'),
('siti.komariiah@gmail.com'),
('gustine.fu999@gmail.com'),
('ennysetiono@msn.com'),
('sartikanganro@gmail.com'),
('mirandahabibie@gmail.com'),
('tokodahliapadang@gmail.com'),
('natanaelsbrn@gmail.com'),
('jelitacosmetic@galeri.com'),
('rkkosmetikviral.anj@gmail.com'),
('sancaytulak26@gmail.com'),
('kelvinhosen@gmail.com'),
('elnazulma@gmail.com'),
('jevrihuang@gmail.com'),
('araitsoke@gmail.com'),
('haju.nutrifood@gmail.com'),
('harwindaharis99@gmail.com'),
('saherasukur92@gmail.com'),
('monamelosi05@gmail.com'),
('pramistiseptarinda@gmail.com'),
('rianadewi15746@gmail.com'),
('frivaldi08@gmail.com'),
('sausankho86@gmail.com'),
('3widjayanti@gmail.com'),
('prinzlina79@gmail.com'),
('restbeauty11@gmail.com'),
('kiarriyasatul@gmail.com'),
('surkiaa56@gmail.com'),
('dellikosmetik@gmail.com'),
('dinafebriana@gmail.com'),
('risnawatiyunus@yahoo.com'),
('pudoopy@gmail.com'),
('serbunganjuk@gmail.com'),
('linda_ho29@yahoo.com'),
('cassmgadm@gmail.com'),
('jennychateriner@gmail.com'),
('thasashop.id@yahoo.com'),
('diancagoodsbywitari@gmail.com'),
('chang3mu@icloud.com'),
('hana_kho@outlook.com'),
('jwl.skinofficial@gmail.com'),
('febri.ilham68@gmail.com'),
('gurl.shopaholic@gmail.com'),
('fenitan00@gmail.com'),
('nadrachanafie@gmail.com'),
('migibeauty1@gmail.com'),
('dewisusianti888@gmail.com'),
('nazwinadya@gmail.com'),
('andinimaylasari@gmail.com'),
('syahrani.cosmetic@gmail.com'),
('primasitaa@gmail.com'),
('spy_solution77@yahoo.com'),
('geeghina@gmail.com'),
('nida.syafa5@gmail.com'),
('financialelzamora@gmail.com'),
('irkosmetikdanskincare@gmail.com'),
('sherlinhosana@gmail.com'),
('sepdiarina@yahoo.com'),
('lumbangaol.ira@gmail.com'),
('aligunawan098@gmail.com'),
('ovarash@gmail.com'),
('rbeauty.storee@gmail.com'),
('cckosmetik77@gmail.com'),
('pinkcosmetich@gmail.com'),
('dhiniemsa@yahoo.com'),
('rulyindah1911@gmail.com'),
('elvina.6789@gmail.com'),
('moeyecosmetic99@gmail.com'),
('sana.19007@mhs.unesa.ac.id'),
('ikasusanti_baru@yahoo.com'),
('indaryani82@gmail.com'),
('hsyapon@gmail.com'),
('citra.ismaya@omniretail.co'),
('thevintagestrawberry@gmail.com'),
('ramadhani.kosmetik@gmail.com'),
('linawijaya2712@yahoo.com'),
('meilings0403@gmail.com'),
('nadyawkk@gmail.com'),
('prellasurabaya@gmail.com'),
('ziyyags@gmail.com'),
('stanley_oh@ymail.com'),
('andre1177az@gmail.com'),
('s.ekaputrirosalinda@gmail.com'),
('beautyland21@icloud.com'),
('javalotuscorp@gmail.com'),
('alxsuherman@gmail.com'),
('fenny3007.kwok@gmail.com'),
('leny_kurniawati@hotmail.com'),
('soputanlady10@gmail.com'),
('lampungbeauty2019@gmail.com'),
('thebeauteebox@gmail.com'),
('tfanixling00@gmail.com'),
('andilesmono06@gmail.com'),
('briggiteleorenza@gmail.com'),
('chanytatiara@gmail.com'),
('financeklinikpiramidajaya@gmail.com'),
('exacarolina@gmail.com'),
('wildhanhafid@gmail.com'),
('himakeup08@gmail.com'),
('riska.sofani@yahoo.com'),
('uciliana35@gmail.com'),
('agusjokin08@gmail.com'),
('madozai96@gmail.com'),
('flo_ver@yahoo.com'),
('dikinarasaki@gmail.com'),
('herul.batch3@gmail.com'),
('rudy.hartono2591@gmail.com'),
('vivi.plm187@gmail.com'),
('hallo@bencuan.id'),
('rahasiamama17@gmail.com'),
('stephzhengg@gmail.com'),
('shelinabeautycare@gmail.com'),
('joelchristianpamula@gmail.com'),
('rethamardjoen11@gmail.com'),
('pomadaivon@gmail.com'),
('divaparis28@gmail.com'),
('wulan.ranpatika@gmail.com'),
('mastoreyadi@gmail.com'),
('febi.muhi@gmail.com'),
('anggriawanferi1991@gmail.com'),
('feliciacolleen80@gmail.com'),
('istie.nodasekisan@gmail.com'),
('melliyniaanugrah@gmail.com'),
('dwiaziza98@gmail.com'),
('alfrianiyelsi@gmail.com'),
('adelia.vn@gmail.com'),
('alvina.iriady@gmail.com'),
('ratnaqisya03@gmail.com'),
('jelitacosmetic.galeri@gmail.com'),
('avex307@gmail.com'),
('rika.wulandaridwan@gmail.com'),
('srihartiniseptember1966@gmail.com'),
('theresia_margareths@yahoo.com'),
('kartikahs89@gmail.com'),
('yanuararifinnur@gmail.com'),
('luthfikhtr@gmail.com'),
('mshopper.id@gmail.com'),
('fifi.liu@yahoo.com'),
('christineeva07@gmail.com'),
('claralverina23@gmail.com'),
('12101na@gmail.com'),
('joanamarvelin.wongso@yahoo.com'),
('lylysiakwee@gmail.com'),
('andyirsaldi@gmail.com'),
('greceliautami@icloud.com'),
('rhayati48@gmail.com'),
('vidya@redroseindo.com'),
('ekanuraini131@gmail.com'),
('kimhiung168@gmail.com'),
('gitaporo@gmail.com'),
('aninditateresa@gmail.com'),
('lexonbeautyofficial@gmail.com'),
('novitaroshaputri@gmail.com'),
('theara.tiara@gmail.com'),
('selvi.chephy@gmail.com'),
('vhaans007@gmail.com'),
('tokosehat130@gmail.com'),
('mirayyacosmetics@gmail.com'),
('kusnen.sota@gmail.com'),
('hokimaxi2020@gmail.com'),
('keikolux@hotmail.com'),
('andreadewi19@gmail.com'),
('harlyskin@gmail.com'),
('viroe.nando@gmail.com'),
('aurelallshop@gmail.com'),
('kosmetikiis@gmail.com'),
('lifanny86@gmail.com'),
('nitamanda28@gmail.com'),
('cantiku8899@gmail.com'),
('sultanagengs3@gmail.com'),
('nurfiitriiyah@gmail.com'),
('nana01iphone@gmail.com'),
('mulyajaaya.motor96@gmail.com'),
('titarahmawati245@gmail.com'),
('marniatihinding@gmail.com'),
('erris.mahardika@gamal.men'),
('isti.qhatsah.nur@gmail.com'),
('dewilasolo@gmail.com'),
('aninditaputri30@gmail.com'),
('aryanto.firdaus@gmail.com'),
('novitaj68@gmail.com'),
('johan_breaker27@yahoo.com'),
('elsaberliya@gmail.com'),
('dewiyuant260693@gmail.com'),
('jeffrynoah@gmail.com'),
('rikasukmawar03@gmail.com'),
('yosua.sasauw1@gmail.com'),
('fitri.miauwh@gmail.com'),
('yuli120797@gmail.com'),
('kamala.tanray@gmail.com'),
('theresiad88@gmail.com'),
('isliana29@gmail.com'),
('chietra.anggraini93@gmail.com'),
('cesario2559@gmail.com'),
('the.secret.of.beauty.id@gmail.com'),
('elsacosmetics@yahoo.com'),
('evinrahmad2@gmail.com'),
('yuhyi.albadali@gmail.com'),
('darwin.saputra.ars@gmail.com'),
('akuntingtim2903@gmail.com'),
('wahyudinrazali4@gmail.com'),
('jwuysan@gmail.com'),
('ruus.silvana@gmail.com'),
('dianmarinaa@gmail.com'),
('dp.anggreani@gmail.com'),
('patricia.ang7@gmail.com'),
('medankosmetik89@gmail.com'),
('ayuputri.ap2201@gmail.com'),
('fikrizia13@gmail.com'),
('beautiva.skincare@gmail.com'),
('gjwproject@gmail.com'),
('pramudya.a.laksono@gmail.com'),
('ssshoptarakan@gmail.com'),
('bungalintong7@gmail.com'),
('ivanakaontole@gmail.com'),
('misel.delini@yahoo.com'),
('dwipujiati1995@gmail.com'),
('vdillahilda@gmail.com'),
('ellenanatasa@gmail.com'),
('bidarishabrina@gmail.com'),
('danimmm44@gmail.com'),
('evitsrikris@gmail.com'),
('gendisbeauty92@gmail.com'),
('eriana.dian0116@gmail.com'),
('eriskhfrd26@gmail.com'),
('jasmineniscalapandya@gmail.com'),
('eryryey03@gmail.com'),
('leessleepwear@gmail.com'),
('yoseptansil6@gmail.com'),
('natdailybeauty@gmail.com'),
('sidoarjosalonsupp@gmail.com'),
('auliarahmadanti77@gmail.com'),
('gustindw@gmail.com'),
('mamihcihuyyy@gmail.com'),
('narabeautytrk@gmail.com'),
('sandikaplg18@gmail.com'),
('20240010013@lspr.edu'),
('maynetav@gmail.com'),
('intandidi88@gmail.com'),
('jeniferpurnomo99@gmail.com'),
('dewisartika192@yahoo.co.id'),
('jokosus.susanto@gmail.com'),
('iswanto.1301@gmail.com'),
('kudo.palopo14@gmail.com'),
('micellangel@nuriglobal.com'),
('theeaanggraeny@gmail.com'),
('andi.or88@gmail.com'),
('rickyoktaviawan20@gmail.com'),
('yunibalisa661@gmail.com'),
('rikiscofieldsap@gmail.com'),
('feliciabeatrixtanner0407@gmail.com'),
('mon_taca@yahoo.com'),
('ardyanawidya@gmail.com'),
('d14na_nonic@yahoo.com'),
('kadirpnm@gmail.com'),
('mita.panji@gmail.com'),
('robbchriszzz13@gmail.com'),
('anicha8490@gmail.com'),
('galuh.acc.kediri@gmail.com'),
('tokosanjayakras.81@gmail.com'),
('vivian.effendi@gmail.com'),
('lisaderia@yahoo.com'),
('anggyfebryna17@gmail.com'),
('yuanita200989@gmail.com'),
('inggycitrasari@gmail.com'),
('musdalifa300396@gmail.com'),
('widdywedariasih3@gmail.com'),
('devinoariska06@gmail.com'),
('idealistina@yahoo.co.id'),
('kelsy18111@gmail.com'),
('elizchang88@gmail.com'),
('kavbeautyofficial@gmail.com'),
('archilagiska@gmail.com'),
('ginawati442@gmail.com'),
('revii.setiadi@gmail.com'),
('nisacuss@gmail.com'),
('eviana001075@gmail.com'),
('moanazone@gmail.com'),
('idabenangraja@gmail.com'),
('babybamscase@gmail.com'),
('bellasetiady@windowslive.com'),
('regina.amalia19@gmail.com'),
('hello.vebeauty@gmail.com'),
('ferinaindrayani@gmail.com'),
('yulia.cindy81@gmail.com'),
('ennakristiana@gmail.com'),
('nur.annisa0@gmail.com'),
('marindarara13@gmail.com'),
('sonyatiaratri2@gmail.com'),
('achmadfauzi1398@gmail.com'),
('fitrijean@gmail.com'),
('zul.hendra1297@gmail.com'),
('csbymagicskin@gmail.com'),
('ridadwi873@gmail.com'),
('grosirkosmetikpekanabaru@gmail.com'),
('gladys.agatha@gmail.com'),
('rahmizarti30@gmail.com'),
('mrs.sitiazizah@gmail.com'),
('paramitaqueena@yahoo.com'),
('uwiecute22@gmail.com'),
('slife557.cs@gmail.com'),
('adindazahra655@gmail.com'),
('lavibeautyandlifestyle@gmail.com'),
('ratna.pratiwi14.rp@gmail.com'),
('yunengazraapriani@gmail.com'),
('sheefaa84@gmail.com'),
('katherinelimanu21@gmail.com'),
('tutiyuniyanti@gmail.com'),
('kartinisarimah@gmail.com'),
('jonastampubolon123@gmail.com'),
('wuisancheni77@gmail.com'),
('shella.madirza888@gmail.com'),
('yulianisetiawan836@gmail.com'),
('janiceechenn@yahoo.com'),
('ferico.ridwan@gmail.com'),
('udjayamandiripgs@gmail.com'),
('budiwijaya1962@gmail.com'),
('rumahkosmetik001@gmail.com'),
('kinanbeautystore@gmail.com'),
('yuniraemah31@yahoo.co.id'),
('barokahbeaute@gmail.com'),
('shrlymarcella@gmail.com'),
('ikrt_2507@yahoo.com'),
('dikofebyan@gmail.com'),
('restyty.riezalina@yahoo.com'),
('ratukosmetik169@gmail.com'),
('faradillahif07@gmail.com'),
('sales@dewicosmetic.com'),
('kadek.arymas@gmail.com'),
('rahmaduwijayanti@gmail.com'),
('fanamaliaauthor@gmail.com'),
('vanessapratama24@gmail.com'),
('gangnamcosmetic109@gmail.com'),
('mayanglatuconsina@gmail.com'),
('lustremaiden@gmail.com'),
('ratihalexa@gmail.com'),
('anindyalarasp@gmail.com'),
('fourayoebeauty@gmail.com'),
('selenabeauty.banjarbaru@gmail.com'),
('destyisniaty@gmail.com'),
('rmdhniannisa15@gmail.com'),
('devimutiah18@gmail.com'),
('ainunmuthiaa@gmail.com'),
('nurhikmah.rasyid@gmail.com'),
('burizma.store@gmail.com'),
('ariefariq4@gmail.com'),
('haniaekap8814@gmail.com'),
('ricomerico240@gmail.com'),
('ekanvt07@gmail.com'),
('helenlim02@gmail.com'),
('lukm.hakm@gmail.com'),
('nur_aisyah1407@icloud.com'),
('serlina.mbc@gmail.com'),
('k.inayah23@gmail.com'),
('marisrisma@yahoo.com'),
('shela.annisa99@gmail.com'),
('angguntrivany@gmail.com'),
('nntheorange@gmail.com'),
('nathaliayaulin23@gmail.com'),
('mrs.gapura@gmail.com'),
('selviathalita92@gmail.com'),
('cynthia.de06@gmail.com'),
('beautemondee@gmail.com'),
('ninikrahmawati486@gmail.com'),
('anst.slvia@gmail.com'),
('beautycarepalu@gmail.com'),
('ririwiduri2002@gmail.com'),
('ilookdaily534@gmail.com'),
('apapunada.id@gmail.com'),
('dellasyaskia6@gmail.com'),
('nadiasalmau@gmail.com'),
('tikamaharaeni19@gmail.com'),
('aansabang@gmail.com'),
('devinatalithanabila98@gmail.com'),
('ennitrisha@gmail.com'),
('marialucyanasunjaya02762@gmail.com'),
('rtnohandayani@gmail.com'),
('nsbeauty06@gmail.com'),
('idapurnamasari0129@gmail.com'),
('msreysantana@gmail.com'),
('aldillaputri5@gmail.com'),
('maderusni25@gmail.com'),
('crystalglow.myshop@gmail.com'),
('dheamuliasari@gmail.com'),
('cindyfdle@gmail.com'),
('laninabeauty.official@gmail.com'),
('nimatussaadah29@gmail.com'),
('merrylaili@gmail.com'),
('wijaya.nanda1810@gmail.com'),
('kadavikadav@gmail.com'),
('anggikurniawati40@gmail.com'),
('mamikikeyu@gmail.com'),
('marlindaabdulrazak@gmail.com'),
('alizhaaa@gmail.com'),
('queenkosmetik20@gmail.com'),
('skincarekupang21@gmail.com'),
('feny.asnawi@gmail.com'),
('shanticahyadi82@gmail.com'),
('zilvanaputri@gmail.com'),
('malikaresmanti@gmail.com'),
('yunisianturi06@gmail.com'),
('beautydarlinggg@gmail.com'),
('lilybeauty.ofc@gmail.com'),
('racyasry@gmail.com'),
('terasbeauty.official@gmail.com'),
('mybeautystory.89@gmail.com'),
('novita.chyntia@yahoo.com'),
('tiffany.kimana@gmail.com'),
('rumahdandan.rd15@gmail.com'),
('desihartanti17@gmail.com'),
('forshare.id@gmail.com'),
('elmiacosmetics@gmail.com'),
('evikartika03@gmail.com'),
('allwomeneeds1403@yahoo.com'),
('nadyahudaya@yahoo.com'),
('drchrysant@gmail.com'),
('yurimeni16@gmail.com'),
('anientya@gmail.com'),
('martina.bernadeta@gmail.com'),
('wulan.dhizhi@gmail.com'),
('andrixue@gmail.com'),
('sitiqulsum308@gmail.com'),
('galaxystoreyogyakarta@gmail.com'),
('iskifitriani@yahoo.co.id'),
('arismunandar6496@gmail.com'),
('agenlingerie.id@gmail.com'),
('indahasmoro90@gmail.com'),
('ksbeautylover@gmail.com'),
('alheabeauty.id@gmail.com'),
('putriitunggal99@gmail.com'),
('ahmadmalangah@gmail.com'),
('perfectionten@gmail.com'),
('ivonsetiono26@gmail.com'),
('agencmb@gmail.com'),
('glowivier@gmail.com'),
('pinkyscosmetics1995@gmail.com'),
('evinakuesnoooo@gmail.com'),
('chennywi0126@icloud.com'),
('ekawahyuni1603@gmail.com'),
('auliaqoriardi21@gmail.com'),
('joyakhineigsoen@gmail.com'),
('susantifajarwati@yahoo.com'),
('ramadhana.selvia2408@gmail.com'),
('andarish.shop@gmail.com'),
('cindytsania@gmail.com'),
('joctora@gmail.com'),
('hannahimanuella@gmail.com'),
('dwiwulandari028@gmail.com'),
('merrychrystin06@gmail.com'),
('fibi.kdi891@gmail.com'),
('suwitosjahari@gmail.com'),
('likestoretlogosari@gmail.com'),
('care.meiyabeauty@gmail.com'),
('ajenganggitasari1@gmail.com'),
('rizkiyanitapinem@gmail.com'),
('sashop.nkc21@gmail.com'),
('lilistiyorini@gmail.com'),
('thebellas1212@gmail.com'),
('be.bellecosmetic@gmail.com'),
('nurlisaaulia@gmail.com'),
('hantybeauty19@gmail.com'),
('mputrisanti@gmail.com'),
('hellolightbit@gmail.com'),
('nadhirauw88@gmail.com'),
('asmiatiakib@gmail.com'),
('ranintya12@gmail.com'),
('afrijalrijal671@gmail.com'),
('ifayusana1993@gmail.com'),
('makeyouup.myu@gmail.com'),
('salbinus.innung@yahoo.com'),
('novia190@gmail.com'),
('evadewim.s@gmail.com'),
('itsmiracle2020@gmail.com'),
('neveltari2703@gmail.com'),
('lieusbudiman@gmail.com'),
('ferisya10@gmail.com'),
('echa.muaniez89@gmail.com'),
('trinarachmawati81@gmail.com'),
('erwinzeey123@gmail.com'),
('sahabat_debora@yahoo.com'),
('dhee2jopankar@gmail.com'),
('yunda.ade11@gmail.com'),
('cyril_steven_alexander_glory@yahoo.com'),
('devisiska32@gmail.com'),
('aureolasa.pratama@gmail.com'),
('ika.angky123@yahoo.com'),
('halimatussakdiyah1997@gmail.com'),
('rahmatjayaj2@gmail.com'),
('jesselynangella08@yahoo.com'),
('famela.ft07@gmail.com'),
('rotinsulufinny@gmail.com'),
('staryisnianti@gmail.com'),
('yulianazayan@gmail.com'),
('fandestian@gmail.com'),
('melindariaslamusnar88@gmail.com'),
('jnwkidswear@gmail.com'),
('wiwin.adriani@gmail.com'),
('febriantisiban25@gmail.com'),
('scoviabybelova@gmail.com'),
('wenny.than@gmail.com'),
('iranipontoh443@gmail.com'),
('hello.lazetta@gmail.com'),
('moullylaroid@gmail.com'),
('laurantjia@gmail.com'),
('dbeautyshop8@gmail.com'),
('godzillaphoneacc3@gmail.com'),
('wiwinstsajaah@gmail.com'),
('rizahani39@gmail.com'),
('dwihartanti_gizi@yahoo.com'),
('fangfangsaputra@gmail.com'),
('amoise.cosmetics@gmail.com'),
('dennyroseiana@gmail.com'),
('nelly.sulistiawati@gmail.com'),
('central.kosmetik1106@gmail.com'),
('marcellino.haryono@gmail.com'),
('veralia.saragih@gmail.com'),
('cefamanusia@gmail.com'),
('arindatrisna33@gmail.com'),
('oketomatala@gmail.com'),
('vilyapangajouw19@gmail.com'),
('faracintadia@gmail.com'),
('adm.elisabethbdg@yahoo.com'),
('cutmiqyal@hotmail.com'),
('harjono.honoris@gmail.com'),
('nandorian98@gmail.com'),
('milalimbong71@gmail.comcom'),
('viliansiregar24@gmail.com'),
('eldeekosmetik@gmail.com'),
('jeane.lelengboto@yahoo.com'),
('lydia.debby@gmail.com'),
('aboutmybusiness11@gmail.com'),
('triple501ara@gmail.com'),
('masfitroh@gmail.com'),
('meisalmis@gmail.com'),
('zackfair232@gmail.com'),
('nakamia_pie@yahoo.com'),
('abeauty.jogja@gmail.com'),
('lenaaska7@gmail.com'),
('zeebacosmetics31@gmail.com'),
('chiangkencana@gmail.com'),
('syaaudriana@gmail.com'),
('nadyaffu@gmail.com'),
('fauziahanisa509@gmail.com'),
('christyciasintaungu@gmail.com'),
('pradnyani.dwi@gmail.com'),
('zarazsby@gmail.com'),
('adewahyupauji@gmail.com'),
('firmantuo@gmail.com'),
('ramadhanilayla@gmail.com'),
('novascafe4@gmail.com'),
('mayaecc@yahoo.com'),
('adeyoan721@gmail.com'),
('stephaniefransss@gmail.com'),
('hermooi.official@gmail.com'),
('ratnaanita170294@gmail.com'),
('agatri.silitonga@gmail.com'),
('dewifitri2403@gmail.com'),
('moehamadsururi14@gmail.com'),
('ariestyayys@gmail.com'),
('heavenlybeauty.adm@gmail.com'),
('ikaabsarih@gmail.com'),
('dhee_amell@yahoo.co.id'),
('devianatanuwijaya@gmail.com'),
('rumah.karara@gmail.com'),
('sreejita.deb@gmail.com'),
('tagdirs.cosmetic@gmail.com'),
('ceviwilly@gmail.com'),
('daniel.khosuma@gmail.com'),
('muhammadyanis12091991@gmail.com'),
('liechintia07@gmail.com'),
('apt.deantigano@gmail.com'),
('ian.tampo22@gmail.com'),
('kunyil505@gmail.com'),
('hongjujen69@gmail.com'),
('wimma.shop@gmail.com'),
('mysamplemart@gmail.com'),
('safitriyuli3@gmail.com'),
('novanindra23@gmail.com'),
('hartantiarline@gmail.com'),
('dianyunus7@gmail.com'),
('aniyt161aan@gmail.com'),
('aestheticbeautycare23@gmail.com'),
('marissarahmaadhania9i30@gmail.com'),
('cecebeautybali@gmail.com'),
('devani.ersa@yahoo.com'),
('windiana10@gmail.com'),
('itaufik55@gmail.com'),
('zhisca_77@yahoo.co.id'),
('jillyanesasiage@gmail.com'),
('mybestiebeauty.bdg@gmail.com'),
('purchasing@bumame-farmasi.com'),
('denisa.denis89@yahoo.com'),
('ranggatedubara@gmail.com'),
('angelialim0311@gmail.com'),
('rindaagustiana@gmail.com'),
('aleshabeautycare57@gmail.com'),
('monpri28@gmail.com'),
('move.hamsari@gmail.com'),
('beautybelle2608@gmail.com'),
('priscillalastyfera@gmail.com'),
('vildarahmawati17@gmail.com'),
('nathaniaa099@gmail.com'),
('noyura@gmail.com'),
('juhatihajibe@gmail.com'),
('winda.christina@gmail.com'),
('mruslir21@gmail.com'),
('siskagsp6@gmail.com'),
('olyviadevita02@gmail.com'),
('ecgirl2023@gmail.com'),
('songlacosmetics@gmail.com'),
('jelsymakeup@gmail.com'),
('vanywidyawati86@gmail.com'),
('ongfreddykusuma@gmail.com'),
('charisthamaysadwisahara@gmail.com'),
('incjodu@gmail.com'),
('mjbeautyblitar@gmail.com'),
('ngeng.yuan27@gmail.com'),
('mybeautymart.id@gmail.com'),
('nabillafr22@gmail.com'),
('dianajennifer118@gmail.com'),
('wetirima9988@gmail.com'),
('shely.proborini@yahoo.com'),
('pak.serba@gmail.com'),
('lili_3038@yahoo.co.id'),
('tallamersiaa@gmail.com'),
('khalisanaura156@gmail.com'),
('milaatysakinah@gmail.com'),
('ucci.arfan@gmail.com'),
('lutfiah.nurhandari@gmail.com'),
('albinadhaja94@gmail.com'),
('dindaty@gmail.com'),
('shopkievanik@gmail.com'),
('zheng.jinde7692@gmail.com'),
('silvi@getvybes.co'),
('muhammadraydevan@gmail.com'),
('alstininoviyantitoar@gmail.com'),
('riahafarul778@gmail.com'),
('nrustam26@gmail.com'),
('gayabyys.wu@gmail.com'),
('lalootust@gmail.com'),
('rina2pan@yahoo.com'),
('disariska@gmail.com'),
('ninu.fira@gmail.com'),
('yuibabaretail@gmail.com'),
('makshifa93@gmail.com'),
('nadzimalaily@gmail.com'),
('nindysyarif@gmail.com'),
('mutiarapesonanganjuk@gmail.com'),
('beautybypelangi@gmail.com'),
('mariyani3412@gmail.com'),
('anitabudi1998@gmail.com'),
('farikhanum@ymail.com'),
('riscaamalia1989@gmail.com'),
('oyha.ciez01@gmail.com'),
('afriasafitri@ymail.com'),
('gitalaksmicosmetic@gmail.com'),
('oktavianimunir@gmail.com'),
('meithaekyh@gmail.com'),
('antouwkeren@gmail.com'),
('meeranova.id@gmail.com'),
('dmuhenti@gmail.com'),
('bima.ajun@gmail.com'),
('sitipluviana@gmail.com'),
('endahpratiwi522@gmail.com'),
('dindalabibah@gmail.com'),
('pusatkosmetikpinky@gmail.com'),
('anjalisibagariang2000@gmail.com'),
('krisnairma15@gmail.com'),
('ocha.rospa@gmail.com'),
('siscabudhyani86@gmail.com'),
('jhenisarykambuno@gmail.com'),
('mp-store4@raenabeauty.com'),
('luckyyosin0913@gmail.com'),
('monica1726@yahoo.co.id'),
('deasyrimanda@gmail.com'),
('pbudianoto@gmail.com'),
('hernispratiwi@gmail.com'),
('lelymelani@yahoo.com'),
('cantiksehat.sby@gmail.com'),
('gunk.fan29@gmail.com'),
('nurhayati01022021@gmail.com'),
('wardahafi@gmail.com'),
('nonikmery256@gmail.com'),
('lismiatilenta69@gmail.com'),
('dewinurhidayah5125@gmail.com'),
('nurhikmah.hasbi@gmail.com'),
('dordiaahss@gmail.com'),
('molly.fh2@gmail.com'),
('avostoresurabaya@gmail.com'),
('alhun.lun@gmail.com'),
('thebeautycare05@gmail.com'),
('mykarol88@gmail.com'),
('angela.sania@yahoo.com'),
('divaa01@ymail.com'),
('p.ariyanti2@gmail.com'),
('rizkycosmetics@gmail.com'),
('claudiayolandpurnomo@gmail.com'),
('ayudea1820@gmail.com'),
('allshopbisnis72@gmail.com'),
('yosephinetan@yahoo.co.id'),
('ayuri.minho@yahoo.com'),
('paolahermawan@yahoo.com'),
('mirna.mirnaaa02@gmail.com'),
('kumaskincare01@gmail.com'),
('officialrabeauty@gmail.com'),
('cacabeauty1234@gmail.com'),
('nadeakayuangellika@gmail.com'),
('linacaterina79@gmail.com'),
('rianishop210@gmail.com'),
('ilhamxmaulanaaa@gmail.com'),
('aratna643@gmail.com'),
('vifi2403@gmail.com'),
('paringdyahdinda@icloud.com'),
('suantysuanty10@gmail.com'),
('nandalisa045@gmail.com'),
('tinylilproject@yahoo.com'),
('arfan.arsya2022@gmail.com'),
('dahliaqueenshop@gmail.com'),
('triantiagus@gmail.com'),
('widyastevani17@gmail.com'),
('adityo_konandar@yahoo.com'),
('zoerosyidh89@gmail.com'),
('yusmane395@gmail.com'),
('tephtephyy@gmail.com'),
('seemser.id@gmail.com'),
('tantinaduu@gmail.com'),
('yannayeshika@gmail.com'),
('juliacsecogati@gmail.com'),
('pheroneid@gmail.com'),
('pauline222bn@gmail.com'),
('dpuspitaprameswari@gmail.com'),
('irnanda.vinka@yahoo.com'),
('agamwijaya89@gmail.com'),
('miniskinjars@gmail.com'),
('faizal@raenabeauty.com'),
('hanaamelinda95@gmail.com'),
('maharanimega39@gmail.com'),
('tia.aprita@gmail.com'),
('m.milanova.sh@gmail.com'),
('belscofabrics@gmail.com'),
('pratamanaufal98@gmail.com'),
('joshanshop@gmail.com'),
('ayuameliasaja@gmail.com'),
('alyadwi00@gmail.com'),
('helloyoumeindonesia@gmail.com'),
('desyrosiyana@gmail.com'),
('isvimega@gmail.com'),
('andrianiyana815@gmail.com'),
('andiakbar.ak@gmail.com'),
('isw11business@gmail.com'),
('guo_fengsheng@yahoo.com'),
('nirmaladewi03@gmail.com'),
('novitheng90@gmail.com'),
('poppymputranto@gmail.com'),
('shellahamayu1997@gmail.com'),
('suparjoariyanti@gmail.com'),
('pipinwahyu80@gmail.com'),
('chryseladarwin.olivia@gmail.com'),
('choisebest64@gmail.com'),
('rafin.trisna@gmail.com'),
('solehac098@gmail.com'),
('ayumirah12@yahoo.com'),
('fasahdi@gmail.com'),
('vindysabeauty@gmail.con'),
('dillalutchu08@gmail.com'),
('hi.dearbella@gmail.com'),
('awili.tri@gmail.com'),
('ardiradityananda@gmail.com'),
('dayanishop474@gmail.com'),
('apriliamega08@gmail.com'),
('vindysabeauty@gmail.com'),
('gilsneedit@gmail.com'),
('meiriannaafs@gmail.com'),
('mantepkebumen66@gmail.com'),
('lisnawatirohmah@gmail.com'),
('mhelydya@gmail.com'),
('apriliandesi@yahoo.co.id'),
('memonaofficial1007@gmail.com'),
('attraversiamobeauty@gmail.com'),
('triyatmoko3116@gmail.com'),
('toxena.shop@gmail.com'),
('fitridwifebriani59@gmail.com'),
('apadotid7@gmail.com'),
('misz_irma@yahoo.com'),
('riofabian112200@gmail.com'),
('indahyuliza7@gmail.com'),
('imasmaslihah2222@gmail.com'),
('letsglowid.jbi@gmail.com'),
('mahreenbeautyskin@gmail.com'),
('aldofiras1607@gmail.com'),
('firdamelia05@gmail.com'),
('hajernihajerni@gmail.com'),
('yunusdarmawan8@gmail.com'),
('fmaharani96@gmail.com'),
('tokoyangtepat@gmail.com'),
('endangdolphin2011@gmail.com'),
('pallawalipu21@gmail.com'),
('pie_buana@yahoo.com'),
('marina.diantika@gmail.com'),
('rihandika34@gmail.com'),
('ngm6756@gmail.com'),
('djonyali59@gmail.com'),
('rismagina02@gmail.com'),
('beautybyasame@gmail.com'),
('gracerushandi@gmail.com'),
('rinianggrayniinank@gmail.com'),
('lin_qiau_hua@yahoo.com'),
('buanainskonsi@gmail.com'),
('cosmetik.giant@gmail.com'),
('reynitaballack@gmail.com'),
('shopkichii88@gmail.com'),
('fadhilahafifah48@yahoo.com'),
('vivaforeva1@gmail.com'),
('sisilia.marshella@yahoo.com'),
('irmhanurjayanti@gmail.com'),
('galuhnur81@gmail.com'),
('gees.hijab@gmail.com'),
('putrimeyanti8@gmail.com'),
('rully0152@gmail.com'),
('buntukk166@gmail.com'),
('williantocindy@gmail.com'),
('nadilla@raenabeauty.com'),
('cindyfreda23@gmail.com'),
('liiyalimz@gmail.com'),
('kikaychan90@gmail.com'),
('tiffanyyaprilia@gmail.com'),
('2017120215@student.unpar.ac.id'),
('23jamesbond11@gmail.com'),
('36yonathan@gmail.com'),
('a.azzahrasyah@gmail.com'),
('a6ustina@gmail.com'),
('abyan.shop97@gmail.com'),
('acelinbeauty@gmail.com'),
('adeevaskincaresemarang@gmail.com'),
('adeyatoko@gmail.com'),
('adimahendraganteng@gmail.com'),
('agatha@raenabeauty.com'),
('agatyalaksmi@gmail.com'),
('agungfadilah810@gmail.com'),
('ahmadluckibawazier@gmail.com'),
('ai.x1.35300@sutomo-mdn.sch.id'),
('alfiatulkhubbi@gmail.com'),
('alfonsocosmetics@gmail.com'),
('alifiarizkiatania@gmail.com'),
('aline_fathin@yahoo.com'),
('alisheretotalk@gmail.com'),
('alithapradita@gmail.com'),
('allaboutskincare312@gmail.com'),
('almardhiyyahs@gmail.com'),
('almirabintangr@gmail.com'),
('alvissyahrin619@gmail.com'),
('alycia_monicaa@yahoo.co.id'),
('amaliakusumaniez@gmail.com'),
('ameicosmetic12@gmail.com'),
('amelianucifera@gmail.com'),
('ameliaresnaw@gmail.com'),
('analiani86@gmail.com'),
('andikharianto978@gmail.com'),
('angelinkayla118@gmail.com'),
('angellim0311@gmail.com'),
('angellina.lady96@gmail.com'),
('anggararnda972@gmail.com'),
('anggrini@raenabeauty.com'),
('anggriprad@gmail.com'),
('anisaauliaabas@gmail.com'),
('anisafarah24@gmail.com'),
('annachf.tan@gmail.com'),
('antodukos@gmail.com'),
('antonisang27@gmail.com'),
('appl3fuji@gmail.com'),
('arisrahmat333@gmail.com'),
('artiwayan14@gmail.com'),
('artrisnandari@gmail.com'),
('arumsekarsari573@gmail.com'),
('asepmirwan1@gmail.com'),
('assyafarrizki@gmail.com'),
('astrsari@gmail.com'),
('atikaputrims97@gmail.com'),
('audi.tabrany@gmail.com'),
('avoskinbeautybandung@gmail.com'),
('avuastore@gmail.com'),
('ayunamadewi@gmail.com'),
('babdungdyfa@gmail.com'),
('beatricetheresia1@gmail.com'),
('beautyshoujo@gmail.com'),
('bella.beautittaid@gmail.com'),
('bellaikne77@gmail.com'),
('bembie07@gmail.com'),
('beningkosmetik59@gmail.com'),
('biutidy@gmail.com'),
('brilianifridayasti@gmail.com'),
('budiondream@gmail.com'),
('business.qhansaanakkami@gmail.com'),
('cahaya.kosmetik.id@gmail.com'),
('cahyanidwisepti20@gmail.com'),
('cantikatya2@gmail.com'),
('catherinerambang620@gmail.com'),
('caty.adja@gmail.com'),
('cderz23@yahoo.com'),
('ceceliasansan8@gmail.com'),
('cerimartgo@gmail.com'),
('chandrahalim714@gmail.com'),
('chen.wong21@gmail.com'),
('cheryl.marsha.heryanto@gmail.com'),
('chococoip@gmail.com'),
('christianyendi@gmail.com'),
('cindyaharvardiana@gmail.com'),
('cinthyaruhantopp1@gmail.com'),
('cinthyaruhantopp3@gmail.com'),
('cisilia268@gmail.com'),
('clarysocimartinez@gmail.com'),
('cosellebeauty@gmail.com'),
('cvindokosmetikasejahtera@gmail.com'),
('d.lilacshop@gmail.com'),
('danielbudisantoso@gmail.com'),
('danielsimanjuntak231@gmail.com'),
('dedywijayamail@gmail.com'),
('definitionbeautyjogja@gmail.com'),
('dektasyaputra1301@gmail.com'),
('dellalisapaly@gmail.com'),
('despielia@gmail.com'),
('despielia92@gmail.com'),
('desyoong21@gmail.com'),
('deviannisme@gmail.com'),
('dewimellinda10@gmail.com'),
('dhevio1426@gmail.com'),
('dianakuliah@gmail.com'),
('dianps.haryanto@yahoo.com'),
('dillaparamita0@gmail.com'),
('dinaapril280@gmail.com'),
('dini.dwiarti3105@gmail.com'),
('dpsbykosme@gmail.com'),
('dwiagustin363@gmail.com'),
('dyas253@gmail.com'),
('dyfacafe@gmail.com'),
('eka.fokus@gmail.com'),
('eleonora@raenabeauty.com'),
('elfayunengsih20@gmail.com'),
('elisiabriana@gmail.com'),
('ellierahardja@gmail.com'),
('elsa.primasari.eps@gmail.com'),
('elsaokta26@gmail.com'),
('endahtriwedanti28@gmail.com'),
('endang.kosmetik1@gmail.com'),
('endangmarbunbbm678@gmail.com'),
('ennykoesrini676@gmail.com'),
('ennysetiono@gmail.com'),
('enokfatimah405@gmail.com'),
('entok345@gmail.com'),
('enungnurhalimah93@gmail.com'),
('envirolisasekar@gmail.com'),
('ernazulianita00@gmail.com'),
('estrellabeautee@gmail.com'),
('etienneskincare@gmail.com'),
('etisuningsih117@gmail.com'),
('evan.zelizta98@gmail.com'),
('evelyn.vio81@gmail.com'),
('evinrahmad4@gmail.com'),
('fajar950@gmail.com'),
('fajaroldman@gmail.com'),
('farah.fbindonesia@gmail.com'),
('faridahsalma@gmail.com'),
('febrina@raenabeauty.com'),
('feliceclarissa90@gmail.com'),
('fennyardisheila@gmail.com'),
('fera.julianti93@gmail.com'),
('feriscainez@gmail.com'),
('fffgh8@gmail.com'),
('fikrizia_insani@yahoo.com'),
('firabanun@gmail.com'),
('fitria_rida@yahoo.com'),
('fitriamalda123@gmail.com'),
('fitriand0192@gmail.com'),
('flavianusferdiaf@gmail.com'),
('flawless.officialshop@gmail.com'),
('flimtysurabayaofficial@gmail.com'),
('fmieayam@gmail.com'),
('freshnglow77@gmail.com'),
('friendhik25@gmail.com'),
('gabriastore@gmail.com'),
('gajahmadawaee@gmail.com'),
('galaticos02@hotmail.com'),
('gbjmarket@gmail.com'),
('givonsal@gmail.com'),
('glammarket64@gmail.com'),
('gloryharahap@gmail.com'),
('grosirmurahsukoharjo5@gmail.com'),
('guo_fengsheng@yahoo.co.id'),
('gustina.denaiyenti21@gmail.com'),
('hanselchan55@gmail.com'),
('hantarancilandak@gmail.com'),
('hardiantinila3@gmail.com'),
('hartono.henny@yahoo.com'),
('hasanyeong8@gmail.com'),
('helbert.simanjuntak@gmail.com'),
('hello.sheetmask@gmail.com'),
('hellopakbu@gmail.com'),
('helmikamanihuruk@gmail.com'),
('herdianametalic@gmail.com'),
('hestydharmayanti933@gmail.com'),
('heymarcell@gmail.com'),
('hijriahr08@gmail.com'),
('hulahulahali@gmail.com'),
('idcosmeticsidcosmetics@gmail.com'),
('ihc.korea@gmail.com'),
('ihccianjur@gmail.com'),
('iis.sugiati83@gmail.com'),
('ijallevine@gmail.com'),
('ikromyafik147@gmail.com'),
('imahgrosir@gmail.com'),
('indahpurwanti4410@gmail.com'),
('indrianimentaruk2@yahoo.com'),
('info.athirabeauty@gmail.com'),
('inggrid.kambuno@yahoo.com'),
('isbeyondstyle@gmail.com'),
('istrinyamalik@gmail.com'),
('iwanku203@gmail.com'),
('jacovcho@gmail.com'),
('jayaananda247@gmail.com'),
('jayde67@genesvjq.com'),
('jazzpro131@gmail.com'),
('jcrshop20@gmail.com'),
('jeliem96@gmail.com'),
('jelysoviana@gmail.com'),
('jesiskaruslan@gmail.com'),
('jessicaa2208@gmail.com'),
('jscang93@gmail.com'),
('jschrynt@gmail.com'),
('juliaviliajulia@gmail.com'),
('jullyangelina85@gmail.com'),
('jumrayana@gmail.com'),
('junidiarisna@gmail.com'),
('jwinarso889@gmail.com'),
('karinaagustin613@yahoo.co.id'),
('katalogskincarekorea@gmail.com'),
('keanoliem3@gmail.com'),
('kekensetiawan@gmail.com'),
('khairunniszahaifa@yahoo.com'),
('kikiseptiana92@gmail.com'),
('klikandshop18@gmail.com'),
('kntz199@gmail.com'),
('kosmetiklancarjaya@gmail.com'),
('kuboykukuh@gmail.com'),
('kunarifin@gmail.com'),
('kurniadi.phan@gmail.com'),
('kyuhaekoinline@gmail.com'),
('kyuhyunkoinline5@gmail.com'),
('lancarjayakosmetik@gmail.com'),
('lanisiska45@gmail.com'),
('laure.devienne@gmail.com'),
('lavoilla@gmail.com'),
('leejaeha31@gmail.com'),
('lenasinaga853@yahoo.com'),
('leo_azzuri@yahoo.com'),
('libbyclaudiar@gmail.com'),
('Liec534@gmail.com'),
('liedhawei@yahoo.com'),
('lina.marlinajkt228@gmail.com'),
('linamay2088@gmail.com'),
('lincebaiku34@gomail.com'),
('lindasekararum@gmail.com'),
('lindaten93@gmail.com'),
('lio.edhen@gmail.com'),
('lionachristina110887@gmail.com'),
('lolithaameliaa.la@gmail.com'),
('lolytha.arina@yahoo.co.id'),
('loverini1508@gmail.com'),
('lricosantoso@gmail.com'),
('luckyluna.id@gmail.com'),
('luckyme2611@gmail.com'),
('lusianaivang@yahoo.com'),
('luvpiggy2312@gmail.com'),
('lyannaming@gmail.com'),
('madya.wa@gmail.com'),
('mahesabeautyandstore@gmail.com'),
('maianton@yahoo.com'),
('mailto.wabisabi@gmail.com'),
('makeupfutura@gmail.com'),
('maramaratus@gmail.com'),
('marciaaact@gmail.com'),
('maria.ariesw87@gmail.com'),
('mariaboons0@gmail.com'),
('marianaulfa11@gmail.com'),
('mariiahulfah123@gmail.com'),
('marlinadiansafitri@gmail.com'),
('maroon16store@gmail.com'),
('marshandaditha@gmail.com'),
('martza.swastikasari@gmail.com'),
('maryani4398@gmail.com'),
('maryavictoryss3@gmail.com'),
('matrasunik@gmail.com'),
('maupesanposter@gmail.com'),
('maximlaundry@yahoo.com'),
('megashinta39@gmail.com'),
('mekarkosmetik.serang@gmail.com'),
('melaplestari2@gmail.com'),
('melindasuriyam01@gmail.com'),
('melisahariyanto14@gmail.com'),
('mentaripuspa59@gmail.com'),
('mh.lifestyles.in@gmail.com'),
('mikanmicheelen@gmail.com'),
('mirzaluzzia123@gmail.com'),
('misluciana@yahoo.com'),
('mitha2904aprilia@gmail.com'),
('mitufaya@gmail.com'),
('mitzukooutfit@gmail.com'),
('mizuharaaya@gmail.com'),
('mohd.nurfitriadin@gmail.com'),
('moildy.id@gmail.com'),
('monalisaflorist@gmail.com'),
('morashopmedan@gmail.com'),
('mr.yung30@gmail.com'),
('muhammad.hidayat.101@gmail.com'),
('mutiaazzahra177@gmail.com'),
('mutiarajesica0209@gmail.com'),
('mykagendis@gmail.com'),
('nadya.desnam@gmail.com'),
('nailavira102@gmail.com'),
('nanalistya22@gmail.com'),
('nandadevie1968@gmail.com'),
('nandipintaa@gmail.com'),
('nari38700@gmail.com'),
('natasyaputri4982@gmail.com'),
('naturrcosmetic@gmail.com'),
('niasepti28@gmail.com'),
('nicoags26@gmail.com'),
('nicolebeautyindonesia@gmail.com'),
('nicoyuganugraha@gmail.com'),
('ninadelinda26@gmail.com'),
('nirmala.sari709@gmail.com'),
('nonaewa@gmail.com'),
('nophaaelfrida@gmail.com'),
('nova.punya@gmail.com'),
('novandy.yohanes@gmail.com'),
('novi0128@gmail.com'),
('novitageraldinetgt@gmail.com'),
('nscollastica@gmail.com'),
('ntyaau26@gmail.com'),
('nuciferaamelia@gmail.com'),
('nugrahapiawai@gmail.com'),
('nur.wazilah@gmail.com'),
('nurazhwa170@gmail.com'),
('nurinasp@gmail.com'),
('nurlaelaramadanti@gmail.com'),
('officialbuyorbye@gmail.com'),
('oktinningrum@gmail.com'),
('opponingrum@gmail.com'),
('oyyisocial@gmail.com'),
('pajerokita@gmail.com'),
('pandridoge@gmail.com'),
('papamarvel_suhendy@yahoo.com'),
('pardosiares@gmail.com'),
('pastiibisaa@gmail.com'),
('pipitsanti999@gmail.com'),
('popoybunny@gmail.com'),
('prakososyam0403@gmail.com'),
('pramita2701@gmail.com'),
('prioritybekasi@gmail.com'),
('properbeauty.id@gmail.com'),
('psalimatulh@gmail.com'),
('puellabeautyshop@gmail.com'),
('puterifedina@gmail.com'),
('putriparapara@gmail.com'),
('putrisildosz@gmail.com'),
('putrivhidi@gmail.com'),
('putryalfionta@yahoo.com'),
('r.alika003@gmail.com'),
('r0n_ny@yahoo.com'),
('radhiah.hasan26@gmail.com'),
('rahayuwrdhn@gmail.com'),
('ranicantikhebat@gmail.com'),
('ratnashary4@gmail.com'),
('raynoldpanjaitan100@gmail.com'),
('regsmakeup@gmail.com'),
('resditamargaretha@gmail.com'),
('reviyuliswan86@gmail.com'),
('ribkanads@gmail.com'),
('richarddarmawanlaidji@gmail.com'),
('rickylie1989@gmail.com'),
('ries091@gmail.com'),
('rikiimpiandes@gmail.com'),
('rikomm822@gmail.com'),
('rinayunikartikaa@gmail.com'),
('rindaariani36@gmail.com'),
('riniismiyanti_94@yahoo.com'),
('ririalijofa@gmail.com'),
('riskalestari014@gmail.com'),
('rkcjawa@yahoo.com'),
('robeth.saputra01@gmail.com'),
('romlahabadsyam@gmail.com'),
('ronnywongsolim@gmail.com'),
('rovihshsh@gmail.com'),
('roviwardanap@gmail.com'),
('roviwardanaputra@gmail.com'),
('rperlita11@gmail.com'),
('rtjayaselalu@gmail.com'),
('rzkamll18@gmail.com'),
('sabithaanisa03@gmail.com'),
('saniaa3095@gmail.com'),
('saniyasch@gmail.com'),
('sansbeauty01@gmail.com'),
('santisujanto@gmail.com'),
('sarah@getvybes.co'),
('sari.astuty12@gmail.com'),
('sarihakim96@gmail.com'),
('sarmutias1@gmail.com'),
('sarmutias2@gmail.com'),
('sarmutias5@gmail.com'),
('seilareisya@gmail.com'),
('selfi.yonghwa08@gmail.com'),
('sendychristians@gmail.com'),
('sepriyanamelly@gmail.com'),
('serlinaepriyanti07@gmail.com'),
('setiawan.laia31@gmail.com'),
('setiawanandrew818@gmail.com'),
('sherlysherlyvi@gmail.com'),
('sholi.hijubpanda@gmail.com'),
('shopalover123@gmail.com'),
('shopbintar@gmail.com'),
('shoujoshopcosmetic@gmail.com'),
('siauwelizabeth@gmail.com'),
('sintafauziah41@gmail.com'),
('siti.lathifatul.k@gmail.com'),
('sitilathifatulkhofi@gmail.com'),
('siuni.reno@gmail.com'),
('siwiberlianti@gmail.com'),
('skincareindoid@gmail.com'),
('skinqueenproject@gmail.com'),
('smcosmeticsub@gmail.com'),
('snana602@gmail.com'),
('snrofi27@gmail.com'),
('soniadepi21@gmail.com'),
('sonie.usman@gmail.com'),
('sreejita@raenabeauty.com'),
('srialfia.san@gmail.com'),
('srihendrawati1@gmail.com'),
('sriyuliani9379@gmail.com'),
('stacia_andani91@yahoo.com'),
('staciaandani91@gmail.com'),
('stasyifa@gmail.com'),
('stefani_eli@ymail.com'),
('stepfanny91@gmail.com'),
('storemajujaya12@gmail.com'),
('sultonudin.madani21@gmail.com'),
('sun.edihtantra@gmail.com'),
('suryakosmetikjogja@gmail.com'),
('suryaniani1960@gmail.com'),
('susantiyap68@gmail.com'),
('suwandikarina61@gmail.com'),
('suwati169@gmail.com'),
('syahlaag@gmail.com'),
('syahliyaf@gmail.com'),
('syahna2128@gmail.com'),
('syahpudin09.183@gmail.com'),
('syifasahb@gmail.com'),
('tagustatang@gmail.com'),
('takiidonlineshopping@gmail.com'),
('talinazulfah@gmail.com'),
('tanmelky@yahoo.com'),
('taraaengg@gmail.com'),
('taspremium88@gmail.com'),
('taufikismail198720@gmail.com'),
('tcahyanti@gmail.com'),
('tfnhtp@gmail.com'),
('the_fortune_eo@yahoo.com'),
('theakirana133@gmail.com'),
('thebeausell@gmail.com'),
('thebeautyneed@gmail.com'),
('theidk.zone@gmail.com'),
('theskindarling@gmail.com'),
('tihanperkasadefitro@gmail.com'),
('tiifandi@gmail.com'),
('timyls@yahoo.com'),
('tina.metro@yahoo.com'),
('tioharianto.allianz@yahoo.com'),
('tjulovely2013@gmail.com'),
('toko.viragrosir88@gmail.com'),
('toko.winars.palopo@gmail.com'),
('tokounikita2@gmail.com'),
('tommy_priatama@ymail.com'),
('topupfu.sp@gmail.com'),
('tyabe888@yahoo.com'),
('ulibasagrc123@gmail.com'),
('umarsikumbang2020@icloud.com'),
('vannychristinna@yahoo.com'),
('varenunggulkarya@gmail.com'),
('veliakatarina@gmail.com'),
('velvetpinkred@gmail.com'),
('vhex307@gmail.com'),
('vidiachen@yahoo.com'),
('vilencyviranyy@gmail.com'),
('vina.astini@yahoo.com'),
('vincenttia23@gmail.com'),
('vinlie2020@gmail.com'),
('violyamerin@gmail.com'),
('viraltoday124@gmail.com'),
('virginiaca09@gmail.com'),
('viserysyvaine@gmail.com'),
('viviyuvita19@gmail.com'),
('wahyudiirwan35@gmail.com'),
('wahyuekajaya@gmail.com'),
('wahyuyana.prasetya@gmail.com'),
('wellington@nihonmart.id'),
('wellypandin76@gmail.com'),
('widoagusputra90@gmail.com'),
('wiwiekapsari@icloud.com'),
('wulan3804@gmail.com'),
('wulandary.sllh@gmail.com'),
('xenpang26@gmail.com'),
('xuanliuli0@gmail.com'),
('yayarafin@gmail.com'),
('yenimaryatin332@gmail.com'),
('yenny.irawati@yahoo.com'),
('yessicasarano16@gmail.com'),
('yogialqarni1807@gmail.com'),
('yogisugianto21@gmail.com'),
('yong2.chan@gmail.com'),
('yooabeaute@gmail.com'),
('ysurjadi@gmail.com'),
('yt40gt@gmail.com'),
('yukireiyuka@gmail.com'),
('yuliacandle@gmail.com'),
('yuliananina19@yahoo.com'),
('yunisri.hartiwi@yahoo.com'),
('yunitadewi23@gmail.com'),
('zabeth_yulie@yahoo.co.id'),
('zahraashop18@gmail.com'),
('zahrabeauty.share@gmail.com'),
('zelmi5009@gmail.com'),
('zharasonline@gmail.com'),
('zivenakbar08@gmail.com'),
('Fanamaliauthor@gmail.com'),
('tjuganteng@gmailcom'),
('ayusisicantik@gmail.com'),
('tsetiyaningsih71@gmail.com'),
('oyyiapple@gmail.com'),
('angellim0311@yahoo.com'),
('fericoridwan@gmail.com'),
('Ikasusanti_story@yahoo.com'),
('hamkyu359@gmail.com');


DROP TABLE raena_analytics.SKU_base_recommendation_base;

CREATE TABLE raena_analytics.SKU_base_recommendation_base AS
SELECT A.sku,
       B.name sku_name ,
       D.name brand_name,
       C.name category_name,
       A.product_type ,
       sum(quantity)total_quantity,
       sum(total_payment_price) total_payment_price,
       sum(total_cogs)total_cogs,
       ((sum(retail_price)-sum(total_cogs))/sum(retail_price))*100 Pre_discount_gm
FROM
  (SELECT sku,
          product_type,
          sum(quantity)quantity,
          sum((retail_price-seller_margin)*quantity) total_payment_price,
          sum(cogs*quantity)total_cogs,
          sum((retail_price-seller_margin)*quantity)retail_price
   FROM raena_analytics.gm_dashboard
   WHERE transaction_date::date>cast('2024-06-23' AS date)-interval'90 days'
     AND cogs IS NOT NULL
     AND cogs>0
   GROUP BY sku,
            product_type)A
INNER JOIN
  (SELECT sku ,
          category_id,
          brand_id,
          name
   FROM raena_catalog_management.product
   WHERE (lower(name) NOT LIKE '%gift %'
          AND lower(name) NOT LIKE '% free %'
          AND lower(name) NOT LIKE '%not for %')
     AND is_archived ='false'
     AND is_delisted ='false') B ON A.sku = B.sku
INNER JOIN
  (SELECT id ,
          name
   FROM raena_catalog_management.category) C ON B.category_id = C.id
INNER JOIN
  (SELECT id ,
          name
   FROM raena_catalog_management.brand) D ON B.brand_id = D.id
GROUP BY 1,
         2,
         3,
         4,
         5 ;


DROP TABLE raena_analytics.reseller_base_recommendation_base;


CREATE TABLE raena_analytics.reseller_base_recommendation_base AS
SELECT reseller_id ,
       A.sku,
       B.name sku_name ,
       D.name brand_name,
       C.name category_name,
       A.product_type ,
       sum(quantity)total_quantity,
       sum(total_payment_price) total_payment_price,
       sum(total_cogs)total_cogs,
       ((sum(retail_price)-sum(total_cogs))/sum(retail_price))*100 Pre_discount_gm --case when  ((sum(discounted_price*quantity)-sum(cogs*quantity))/sum(discounted_price*quantity))*100>10 then 'DDB' else 'Offender' end GM_type
FROM (SELECT sku,reseller_id ,
reseller_email,
          product_type,
          sum(quantity)quantity,
          sum((retail_price-seller_margin)*quantity) total_payment_price,
          sum(cogs*quantity)total_cogs,
          sum((retail_price-seller_margin)*quantity)retail_price
   FROM raena_analytics.gm_dashboard
   WHERE transaction_date::date>cast('2024-06-23' AS date)-interval'90 days'
     AND cogs IS NOT NULL
     AND cogs>0
     AND reseller_id IS NOT NULL
   GROUP BY sku,
            product_type,reseller_id,reseller_email ) A
INNER JOIN (SELECT sku ,
          category_id,
          brand_id,
          name
   FROM raena_catalog_management.product) B ON A.sku = B.sku
INNER JOIN (SELECT id ,
          name
   FROM raena_catalog_management.category) C ON B.category_id = C.id
INNER JOIN  (SELECT id ,
          name
   FROM raena_catalog_management.brand) D ON B.brand_id = D.id
INNER JOIN raena_analytics.recommendation_power_seller_base BB ON A.reseller_email = BB.email
GROUP BY 1,
         2,
         3,
         4,
         5,
         6;

DROP TABLE raena_analytics.reseller_base_recommendation_base_stage1;


CREATE TABLE raena_analytics.reseller_base_recommendation_base_stage1 AS
SELECT *,
       CASE
           WHEN ((total_payment_price-total_cogs)/total_payment_price)*100>=10 THEN 'DDB'
           ELSE 'Offender'
       END GM_type
FROM raena_analytics.reseller_base_recommendation_base;

DROP TABLE IF EXISTS raena_analytics.raw_scraping_data;

CREATE TABLE raena_analytics.raw_scraping_data AS
SELECT
    E.raena_product_sku,
    F.name AS SKU_name,
    E.rce_product_id,
    E.rce_variant_id,
    A.category_name,
    A.brand_name,
    A.product_page_url,
    A.rce_source_product_name,
    A.product_variant_name,
    A.product_variant_price,
    A.product_variant_price_before_discount,
    A.product_sold_total,
    A.product_sold,
    A.product_price_min,
    A.product_price_min_before_discount,
    A.product_price_max,
    A.product_price_max_before_discount,
    CAST(percentage_match AS DECIMAL(22, 2)) AS percentage_match,
    A.ratings
FROM
    raena_analytics.raena_shopee_product_mapping E
LEFT JOIN (
    SELECT
        A.id AS rce_product_id,
        D.id AS rce_product_varient_id,
        B.category_name,
        C.brand_name,
        product_page_url,
        rce_source_product_name,
        product_variant_name,
        case when product_variant_price is null then 0 WHEN product_variant_price = 'None' THEN 0 WHEN product_variant_price ~ '^[0-9]+$' THEN CAST(product_variant_price AS BIGINT) ELSE 0 end  / 10000 AS product_variant_price,
        case when product_variant_price_before_discount is null then 0 WHEN product_variant_price_before_discount = 'None' THEN 0 WHEN product_variant_price_before_discount ~ '^[0-9]+$' THEN CAST(product_variant_price_before_discount AS BIGINT) ELSE 0 end  / 10000 AS product_variant_price_before_discount,
        product_sold_total,
        product_sold,
        case when product_price_min is null then 0 WHEN product_price_min = 'None' THEN 0 WHEN product_price_min ~ '^[0-9]+$' THEN CAST(product_price_min AS BIGINT) ELSE 0 end  / 10000 AS product_price_min,
        case when product_price_min_before_discount is null then 0 WHEN product_price_min_before_discount = 'None' THEN 0 WHEN product_price_min_before_discount ~ '^[0-9]+$' THEN CAST(product_price_min_before_discount AS BIGINT) ELSE 0 end  / 10000 AS product_price_min_before_discount,
        case when product_price_max is null then 0 WHEN product_price_max = 'None' THEN 0 WHEN product_price_max ~ '^[0-9]+$' THEN CAST(product_price_max AS BIGINT) ELSE 0 end  / 10000 AS product_price_max,
        case when product_price_max_before_discount is null then 0 WHEN product_price_max_before_discount = 'None' THEN 0 WHEN product_price_max_before_discount ~ '^[0-9]+$' THEN CAST(product_price_max_before_discount AS BIGINT) ELSE 0 end  / 10000 AS product_price_max_before_discount,
        ratings
    FROM
        raena_spider_management.rce_product A
    LEFT JOIN raena_spider_management.rce_category B ON A.rce_category_id = B.id
    LEFT JOIN raena_spider_management.rce_brand C ON A.rce_brand_id = CAST(C.id AS VARCHAR)
    LEFT JOIN raena_spider_management.rce_product_variant D ON A.id = D.rce_product_id
) A ON E.rce_product_id = CAST(A.rce_product_id AS VARCHAR)
AND REPLACE(E.rce_variant_id, '.0', '') = REPLACE(CAST(A.rce_product_varient_id AS VARCHAR), ',', '')
LEFT JOIN raena_catalog_management.product F ON E.raena_product_sku = F.sku;


DROP TABLE IF EXISTS raena_analytics.raw_scraping_data_stage ;


CREATE TABLE raena_analytics.raw_scraping_data_stage AS
SELECT A.*
FROM raena_analytics.raw_scraping_data A
INNER JOIN
  (SELECT raena_product_sku,
          max(percentage_match) percentage_match
   FROM raena_analytics.raw_scraping_data
   GROUP BY 1) B ON A.raena_product_sku = B.raena_product_sku
AND A.percentage_match =B.percentage_match;


DROP TABLE IF EXISTS raena_analytics.sku_sales_factor;


CREATE TABLE raena_analytics.sku_sales_factor AS
SELECT SKU,
       cast(cast(sum(B.total_quantity*3) AS decimal(22,2))/cast(SUM(A.total_quantity) AS decimal(22,2)) AS decimal(22,2)) sale_factor
FROM raena_analytics.SKU_base_recommendation_base A
LEFT JOIN
  (SELECT raena_product_sku,
          sum(DISTINCT product_sold) total_quantity
   FROM raena_analytics.raw_scraping_data_stage
   GROUP BY 1) B ON A.sku = B.raena_product_sku
WHERE A.Pre_discount_gm>=10
GROUP BY 1;


DROP TABLE IF EXISTS raena_analytics.recommendation_on_low_sku_task1;


CREATE TABLE raena_analytics.recommendation_on_low_sku_task1 AS
SELECT C.mobile Reseller_mobile ,
       C.email reseller_email,
       A.sku,
       A.sku_name,
       A.brand_name,
       A.category_name ,
       A.product_type ,
       Total_quantity,
       total_payment_price,
       total_cogs,
       A.pre_discount_gm,
       coalesce(B.sale_factor,0) sale_factor,
       A.pre_discount_gm*coalesce(B.sale_factor,1) sorting
FROM
  (SELECT *
   FROM raena_analytics.reseller_base_recommendation_base_stage1
   WHERE Gm_type = 'DDB') A
INNER JOIN
  (SELECT mobile,
          email,
          id
   FROM raena_user_management.user) C ON A.reseller_id = cast(C.id AS varchar)
INNER JOIN
  (SELECT sku ,
          pre_discount_gm
   FROM raena_analytics.SKU_base_recommendation_base) D ON A.sku = D.sku
AND D.pre_discount_gm >=10
INNER JOIN raena_analytics.sku_in_stock E ON A.sku = E.sku
AND E.in_stock >=10
LEFT JOIN raena_analytics.sku_sales_factor B ON A.sku = B.sku;
---------------------------------------------task 2 ---------------





DROP TABLE raena_analytics.SKU_base_recommendation_base_v2;


CREATE TABLE raena_analytics.SKU_base_recommendation_base_v2 AS
SELECT A.sku,
       ((sum((A.retail_price-seller_margin) *quantity)-sum(A.cogs*quantity))/sum((A.retail_price-seller_margin)*quantity))*100 Pre_discount_gm
FROM raena_analytics.gm_dashboard A
WHERE transaction_date::date>cast('2024-06-23' as date)-interval'90 days'
  AND A.cogs IS NOT NULL
  AND A.cogs>0
  AND tier_name ='GOLD'
GROUP BY 1;

DROP TABLE IF EXISTS raena_analytics.recommendation_base_historical_data_offender;


CREATE TABLE raena_analytics.recommendation_base_historical_data_offender AS
SELECT reseller_id ,
       A.sku ,
       A.sku_name ,
       A.brand_name ,
       A.category_name,
       A.product_type,
       mapping_group_base recommended_sku,
       E.sku_name recommended_sku_name,
       E.brand_name recommended_brand_name,
       E.category_name recommended_category_name,
       E.product_type recommended_product_type,
       percent_concern_match recommended_concern_match_percent,
       percent_ingredient_match recommended_ingredient_match_percent,
       sale_factor ,
       Pre_discount_gm
FROM
  (SELECT reseller_id ,
          sku ,
          sku_name ,
          brand_name,
          category_name,
          product_type
   FROM raena_analytics.reseller_base_recommendation_base_stage1
   WHERE gm_type ='Offender') A
LEFT JOIN raena_analytics.raw_ingredient_mapping_table B ON A.sku = B.group_base
LEFT JOIN raena_analytics.sku_sales_factor C ON B.mapping_group_base = C.sku
LEFT JOIN raena_analytics.SKU_base_recommendation_base_v2 D ON B.mapping_group_base = D.sku
AND Pre_discount_gm>=10
LEFT JOIN
  (SELECT DISTINCT B.sku ,
                   B.name sku_name ,
                   D.name brand_name,
                   C.name category_name,
                   B.product_type
   FROM
     (SELECT sku,
             name,
             product_type,
             category_id,
             brand_id
      FROM raena_catalog_management.product
      WHERE (lower(name) NOT LIKE '%gift %'
             AND lower(name) NOT LIKE '% free %'
             AND lower(name) NOT LIKE '%not for %')
        AND is_archived ='false'
        AND is_delisted ='false') B
   INNER JOIN
     (SELECT id,
             name
      FROM raena_catalog_management.category) C ON B.category_id = C.id
   INNER JOIN
     (SELECT id,
             name
      FROM raena_catalog_management.brand) D ON B.brand_id = D.id ) E ON B.mapping_group_base= E.SKU;


  DROP TABLE IF EXISTS raena_analytics.recommendation_base_historical_data_ddb;


CREATE TABLE raena_analytics.recommendation_base_historical_data_ddb AS
SELECT reseller_id ,
       A.sku ,
       A.sku_name ,
       A.brand_name ,
       A.category_name,
       A.product_type,
       A.Pre_discount_gm reseller_pre_discount_gm,
       mapping_group_base recommended_sku,
       E.sku_name recommended_sku_name,
       E.brand_name recommended_brand_name,
       E.category_name recommended_category_name,
       E.product_type recommended_product_type,
       percent_concern_match recommended_concern_match_percent,
       percent_ingredient_match recommended_ingredient_match_percent,
       sale_factor ,
       D.Pre_discount_gm,
       in_stock
FROM
  (SELECT reseller_id ,
          sku ,
          sku_name ,
          brand_name,
          category_name,
          product_type,
          Pre_discount_gm
   FROM raena_analytics.reseller_base_recommendation_base_stage1
   WHERE gm_type ='DDB') A
LEFT JOIN raena_analytics.raw_ingredient_mapping_table B ON A.sku = B.group_base
LEFT JOIN raena_analytics.sku_sales_factor C ON A.SKU = C.sku
LEFT JOIN raena_analytics.SKU_base_recommendation_base_v2 D ON B.mapping_group_base = D.sku
AND D.Pre_discount_gm>=10
LEFT JOIN raena_analytics.sku_in_stock F ON B.mapping_group_base = F.sku
LEFT JOIN
  (SELECT DISTINCT B.sku ,
                   B.name sku_name ,
                   D.name brand_name,
                   C.name category_name,
                   B.product_type
   FROM
     (SELECT sku,
             name,
             product_type,
             category_id,
             brand_id
      FROM raena_catalog_management.product
      WHERE (lower(name) NOT LIKE '%gift %'
             AND lower(name) NOT LIKE '% free %'
             AND lower(name) NOT LIKE '%not for %')
        AND is_archived ='false'
        AND is_delisted ='false') B
   INNER JOIN
     (SELECT id,
             name
      FROM raena_catalog_management.category) C ON B.category_id = C.id
   INNER JOIN
     (SELECT id,
             name
      FROM raena_catalog_management.brand) D ON B.brand_id = D.id ) E ON B.mapping_group_base= E.SKU;

  DROP TABLE raena_analytics.recommentdation_offender_sku_concern;


CREATE TABLE raena_analytics.recommentdation_offender_sku_concern AS
SELECT B.reseller_id ,
       C.email reseller_email,
       C.mobile reseller_mobile ,
       sku ,
       sku_name ,
       brand_name ,
       category_name,
       product_type,
       recommended_sku,
       recommended_sku_name,
       recommended_brand_name,
       recommended_category_name,
       recommended_product_type,
       recommended_concern_match_percent,
       sale_factor ,
       Pre_discount_gm
FROM raena_analytics.recommendation_base_historical_data_offender B
INNER JOIN (select id , email,mobile from raena_user_management.user) C ON B.reseller_id = cast(C.id as varchar)
WHERE recommended_concern_match_percent>0 and Pre_discount_gm is not null
ORDER BY 1,
         16 DESC;


 DROP TABLE raena_analytics.recommentdation_offender_sku_ingredient;


CREATE TABLE raena_analytics.recommentdation_offender_sku_ingredient AS
SELECT reseller_id ,
       C.email reseller_email,
       C.mobile reseller_mobile ,
       sku ,
       sku_name ,
       brand_name ,
       category_name,
       product_type,
       recommended_sku,
       recommended_sku_name,
       recommended_brand_name,
       recommended_category_name,
       recommended_product_type,
       recommended_ingredient_match_percent,
       sale_factor ,
       Pre_discount_gm
FROM raena_analytics.recommendation_base_historical_data_offender B
INNER JOIN  (select id , email,mobile from raena_user_management.user) C ON B.reseller_id = cast(C.id as varchar)
AND recommended_ingredient_match_percent>0 and Pre_discount_gm is not null
ORDER BY 1,
         16 DESC ;


 DROP TABLE IF EXISTS raena_analytics.recommentdation_ddb_sku_concern ;


CREATE TABLE raena_analytics.recommentdation_ddb_sku_concern AS
SELECT B.reseller_id ,
       C.email reseller_email,
       C.mobile reseller_mobile ,
       B.sku ,
       B.sku_name ,
       B.brand_name ,
       B.category_name,
       product_type,
       recommended_sku,
       recommended_sku_name,
       recommended_brand_name,
       recommended_category_name,
       recommended_product_type,
       recommended_concern_match_percent,
       sale_factor ,
       Pre_discount_gm
FROM raena_analytics.recommendation_base_historical_data_ddb B
INNER JOIN  (select id , email,mobile from raena_user_management.user) C ON B.reseller_id = cast(C.id as varchar)
WHERE recommended_concern_match_percent>0
  AND in_stock<50
  and Pre_discount_gm is not null
UNION
SELECT DISTINCT B.reseller_id ,
                C.email reseller_email,
                C.mobile reseller_mobile ,
                B.sku ,
                B.sku_name ,
                B.brand_name ,
                B.category_name,
                product_type,
                B.sku ,
                B.sku_name ,
                B.brand_name ,
                B.category_name,
                product_type,
                100 ,
                1 sale_factor,
                  reseller_pre_discount_gm
FROM raena_analytics.recommendation_base_historical_data_ddb B
INNER JOIN  (select id , email,mobile from raena_user_management.user) C ON B.reseller_id = cast(C.id as varchar)
WHERE in_stock>50 and reseller_pre_discount_gm>10;

DROP TABLE IF EXISTS raena_analytics.recommentdation_ddb_sku_ingredient ;


CREATE TABLE raena_analytics.recommentdation_ddb_sku_ingredient AS
SELECT B.reseller_id ,
       C.email reseller_email,
       C.mobile reseller_mobile ,
       B.sku ,
       B.sku_name ,
       B.brand_name ,
       B.category_name,
       product_type,
       recommended_sku,
       recommended_sku_name,
       recommended_brand_name,
       recommended_category_name,
       recommended_product_type,
       recommended_ingredient_match_percent,
       sale_factor ,
       Pre_discount_gm
FROM raena_analytics.recommendation_base_historical_data_ddb B
INNER JOIN (select id , email,mobile from raena_user_management.user) C ON B.reseller_id = cast(C.id as varchar)
WHERE recommended_ingredient_match_percent>0
  AND in_stock<50
  and Pre_discount_gm is not null
UNION
SELECT DISTINCT B.reseller_id ,
                C.email reseller_email,
                C.mobile reseller_mobile ,
                B.sku ,
                B.sku_name ,
                B.brand_name ,
                B.category_name,
                product_type,
                B.sku ,
                B.sku_name ,
                B.brand_name ,
                B.category_name,
                product_type,
                100 ,
                1 sale_factor,
                  reseller_pre_discount_gm
FROM raena_analytics.recommendation_base_historical_data_ddb B
INNER JOIN (select id , email,mobile from raena_user_management.user) C ON B.reseller_id = cast(C.id as varchar)
WHERE in_stock>50
and reseller_pre_discount_gm >=10;

DROP TABLE raena_analytics.recommentdation_sku_ingredient;


CREATE TABLE raena_analytics.recommentdation_sku_ingredient AS
SELECT Reseller_email ,
       Reseller_mobile ,
       Recommended_sku ,
       Recommended_sku_name,
       recommended_category_name ,
       recommended_brand_name ,
       recommended_product_type,
       Ingredient_match,
       Recommended_pre_discount_gm,
       sale_factor ,
       (Ingredient_match*coalesce(sale_factor,1)*Recommended_pre_discount_gm) sorting,
       cast(tier_price AS decimal(22,2)) gold_price
FROM
  (SELECT distinct Reseller_email ,
          Reseller_mobile ,
          Recommended_sku ,
          Recommended_sku_name,
          recommended_category_name ,
          recommended_brand_name ,
          recommended_product_type,
          Ingredient_match,
          sale_factor,
          Recommended_pre_discount_gm
   FROM
     (SELECT distinct Reseller_email ,
             Reseller_mobile ,
             Recommended_sku ,
             Recommended_sku_name,
             recommended_category_name ,
             recommended_brand_name ,
             recommended_product_type,
             recommended_ingredient_match_percent Ingredient_match,
             cast(sale_factor AS decimal(22,2)) sale_factor,
             pre_discount_gm Recommended_pre_discount_gm
      FROM raena_analytics.recommentdation_ddb_sku_ingredient
      WHERE pre_discount_gm IS NOT NULL
      and category_name = recommended_category_name
      and product_type=recommended_product_type) A
   UNION SELECT distinct Reseller_email ,
                Reseller_mobile ,
                Recommended_sku ,
                Recommended_sku_name,
                recommended_category_name ,
                recommended_brand_name ,
                recommended_product_type,
                Ingredient_match,
                sale_factor,
                Recommended_pre_discount_gm
   FROM
     (SELECT distinct Reseller_email ,
             Reseller_mobile ,
             Recommended_sku ,
             Recommended_sku_name,
             recommended_category_name ,
             recommended_brand_name ,
             recommended_product_type,
             recommended_ingredient_match_percent Ingredient_match,
             sale_factor,
             pre_discount_gm Recommended_pre_discount_gm
      FROM raena_analytics.recommentdation_offender_sku_ingredient
      WHERE pre_discount_gm IS NOT NULL
      and category_name = recommended_category_name
      and product_type=recommended_product_type) A)AA
      inner join (select sku,  json_extract_path_text(tier_price,'bf645e97-8a48-4977-8367-e987489760f9',true) tier_price from raena_catalog_management.product) BB on AA.Recommended_sku= BB.sku
      inner JOIN raena_analytics.sku_in_stock F ON AA.Recommended_sku = F.sku and F.in_Stock>=10
ORDER BY reseller_email,
         sorting DESC;


DROP TABLE raena_analytics.recommentdation_sku_ingredient_purchase;


CREATE TABLE raena_analytics.recommentdation_sku_ingredient_purchase AS
SELECT Reseller_email ,
       Reseller_mobile ,
       Recommended_sku ,
       AA.sku,
             AA.sku_name,
             AA.category_name ,
             AA.brand_name ,
             AA.product_type,
             cast(tier_price AS decimal(22,2))gold_price
FROM
  (SELECT distinct Reseller_email ,
          Reseller_mobile ,
          Recommended_sku ,
          sku,
             sku_name,
             category_name ,
             brand_name ,
             product_type
   FROM
     (SELECT distinct Reseller_email ,
             Reseller_mobile ,
             Recommended_sku ,
             sku,
             sku_name,
             category_name ,
             brand_name ,
             product_type
      FROM raena_analytics.recommentdation_ddb_sku_ingredient
      WHERE pre_discount_gm IS NOT NULL
      and category_name = recommended_category_name
      and product_type=recommended_product_type) A
   UNION SELECT distinct Reseller_email ,
                Reseller_mobile ,
                Recommended_sku,
                sku,
             sku_name,
             category_name ,
             brand_name ,
             product_type
   FROM
     (SELECT distinct Reseller_email ,
             Reseller_mobile ,
             Recommended_sku ,
             sku,
             sku_name,
             category_name ,
             brand_name ,
             product_type
      FROM raena_analytics.recommentdation_offender_sku_ingredient
      WHERE pre_discount_gm IS NOT NULL
      and category_name = recommended_category_name
      and product_type=recommended_product_type) A)AA
      inner join (select sku,  json_extract_path_text(tier_price,'bf645e97-8a48-4977-8367-e987489760f9',true) tier_price from raena_catalog_management.product) BB on AA.sku= BB.sku
      inner JOIN raena_analytics.sku_in_stock F ON AA.Recommended_sku = F.sku and F.in_Stock>=10
ORDER BY reseller_email;



DROP TABLE raena_analytics.recommentdation_sku_concern;


CREATE TABLE raena_analytics.recommentdation_sku_concern AS
SELECT Reseller_email ,
       Reseller_mobile ,
       Recommended_sku ,
       Recommended_sku_name,
       recommended_category_name ,
       recommended_brand_name ,
       recommended_product_type,
       concern_match,
       Recommended_pre_discount_gm,
       sale_factor ,
       concern_match*coalesce(sale_factor,1)*Recommended_pre_discount_gm sorting,
       cast(tier_price AS decimal(22,2)) gold_price
FROM
  (SELECT Reseller_email ,
          Reseller_mobile ,
          Recommended_sku ,
          Recommended_sku_name,
          recommended_category_name ,
          recommended_brand_name ,
          recommended_product_type,
          concern_match,
          sale_factor,
          Recommended_pre_discount_gm
   FROM
     (SELECT Reseller_email ,
             Reseller_mobile ,
             Recommended_sku ,
             Recommended_sku_name,
             recommended_category_name ,
             recommended_brand_name ,
             recommended_product_type,
             recommended_concern_match_percent concern_match,
             sale_factor,
             pre_discount_gm Recommended_pre_discount_gm
      FROM raena_analytics.recommentdation_ddb_sku_concern
      WHERE pre_discount_gm IS NOT NULL
      and category_name = recommended_category_name
      and product_type=recommended_product_type) A
   UNION SELECT Reseller_email ,
                Reseller_mobile ,
                Recommended_sku ,
                Recommended_sku_name,
                recommended_category_name ,
                recommended_brand_name ,
                recommended_product_type,
                concern_match,
                sale_factor,
                Recommended_pre_discount_gm
   FROM
     (SELECT Reseller_email ,
             Reseller_mobile ,
             Recommended_sku ,
             Recommended_sku_name,
             recommended_category_name ,
             recommended_brand_name ,
             recommended_product_type,
             recommended_concern_match_percent concern_match,
             sale_factor,
             pre_discount_gm Recommended_pre_discount_gm
      FROM raena_analytics.recommentdation_offender_sku_concern
      WHERE pre_discount_gm IS NOT NULL
      and category_name = recommended_category_name
      and product_type=recommended_product_type) A)AA
      inner join (select sku,  json_extract_path_text(tier_price,'bf645e97-8a48-4977-8367-e987489760f9',true) tier_price from raena_catalog_management.product) BB on AA.Recommended_sku= BB.sku
      inner JOIN raena_analytics.sku_in_stock F ON AA.Recommended_sku = F.sku and F.in_Stock>=10
ORDER BY reseller_email,
         sorting DESC;

DROP TABLE raena_analytics.recommentdation_sku_concern_purchase;


CREATE TABLE raena_analytics.recommentdation_sku_concern_purchase AS
SELECT Reseller_email ,
       Reseller_mobile ,
       Recommended_sku ,
       AA.sku,
             AA.sku_name,
             AA.category_name ,
             AA.brand_name ,
             AA.product_type,
       cast(tier_price AS decimal(22,2)) gold_price
FROM
  (SELECT Reseller_email ,
          Reseller_mobile ,
          Recommended_sku ,
          sku,
       sku_name,
       category_name ,
       brand_name ,
       product_type
   FROM
     (SELECT Reseller_email ,
             Reseller_mobile ,
             Recommended_sku ,
             sku,
       sku_name,
       category_name ,
       brand_name ,
       product_type
      FROM raena_analytics.recommentdation_ddb_sku_concern
      WHERE pre_discount_gm IS NOT NULL
      and category_name = recommended_category_name
      and product_type=recommended_product_type) A
   UNION SELECT Reseller_email ,
                Reseller_mobile ,
                Recommended_sku ,
                sku,
       sku_name,
       category_name ,
       brand_name ,
       product_type
   FROM
     (SELECT Reseller_email ,
             Reseller_mobile ,
             Recommended_sku ,
             sku,
       sku_name,
       category_name ,
       brand_name ,
       product_type
      FROM raena_analytics.recommentdation_offender_sku_concern
      WHERE pre_discount_gm IS NOT NULL
      and category_name = recommended_category_name
      and product_type=recommended_product_type) A)AA
      inner join (select sku, json_extract_path_text(tier_price,'bf645e97-8a48-4977-8367-e987489760f9',true) tier_price from raena_catalog_management.product) BB on AA.sku= BB.sku
      inner JOIN raena_analytics.sku_in_stock F ON AA.Recommended_sku = F.sku and F.in_Stock>=10
ORDER BY reseller_email;

 -----------------------------------------------Task 3 -------------------------------(completed)
--inner join (select distinct id as order_id , json_extract_path_text(reseller_info,'province',TRUE) reseller_province
-- from raena_order_management.order
-- where created_at::date>dateadd(DAY,-91,'2024-06-23') and payment_status='Paid') AA on A.external_id = AA.order_id


DROP TABLE raena_analytics.SKU_base_recommendation_base_t3 ;


CREATE TABLE raena_analytics.SKU_base_recommendation_base_t3 AS
SELECT A.sku,
       B.name sku_name ,
       D.name brand_name,
       C.name category_name,
       A.product_type ,
       shipping_province,
       sum(quantity)total_quantity,
       sum((A.retail_price-seller_margin)*quantity) total_payment_price,
       sum(A.cogs*quantity)total_cogs,
       ((sum((A.retail_price-seller_margin)*quantity)-sum(A.cogs*quantity))/sum((A.retail_price-seller_margin)*quantity))*100 Pre_discount_gm
FROM raena_analytics.gm_dashboard A
INNER JOIN raena_catalog_management.product B ON A.sku = B.sku
INNER JOIN raena_catalog_management.category C ON B.category_id = C.id
INNER JOIN raena_catalog_management.brand D ON B.brand_id = D.id
WHERE transaction_date::date>cast('2024-06-23' as date)-interval'90 days'
  AND A.cogs IS NOT NULL
  AND A.cogs>0
  and (lower(B.name) not like '%gift %'
and lower(B.name) not like '% free %'
and lower(B.name) not like '%not for %')
and B.is_archived ='false'
and B.is_delisted ='false'
GROUP BY 1,
         2,
         3,
         4,
         5,
         6 ;

DROP TABLE raena_analytics.reseller_base_recommendation_base_t3;


CREATE TABLE raena_analytics.reseller_base_recommendation_base_t3 AS
SELECT reseller_id ,
       A.sku,
       case when shipping_to ='Customer' then shipping_province end as dropshipping_province,
       case when shipping_to ='Reseller' then shipping_province end as reseller_province,
       sum(quantity)total_quantity,
       sum((A.retail_price-seller_margin) *quantity) total_payment_price,
       sum(A.cogs*quantity)total_cogs,
       ((sum((A.retail_price-seller_margin)*quantity)-sum(A.cogs*quantity))/sum((A.retail_price-seller_margin)*quantity))*100 Post_discount_gm --case when  ((sum(discounted_price*quantity)-sum(cogs*quantity))/sum(discounted_price*quantity))*100>10 then 'DDB' else 'Offender' end GM_type
FROM raena_analytics.gm_dashboard A
INNER JOIN
  (SELECT DISTINCT id AS order_id ,
                   shipping_to
   FROM raena_order_management.order
   WHERE created_at::date>cast('2024-06-23' as date)-interval'180 days'
     AND payment_status='Paid') AA ON A.external_id = AA.order_id
INNER JOIN raena_analytics.recommendation_power_seller_base BB ON A.reseller_email = BB.email
WHERE transaction_date::date>cast('2024-06-23' as date)-interval'180 days'
  AND A.cogs IS NOT NULL
  AND A.cogs>0
  AND reseller_id IS NOT NULL
  AND order_placed_by ='Admin Panel'
  AND shipping_to <> 'Marketplace'
GROUP BY 1,
         2,
         3,
         4;

DROP TABLE raena_analytics.reseller_base_recommendation_base_stage1_t3;


CREATE TABLE raena_analytics.reseller_base_recommendation_base_stage1_t3 AS
SELECT *,
       CASE
           WHEN ((total_payment_price-total_cogs)/total_payment_price)*100>10 THEN 'DDB'
           ELSE 'Offender'
       END GM_type
FROM raena_analytics.reseller_base_recommendation_base_t3;


drop table if exists raena_analytics.reseller_base_recommendation_base_stage1_t3_v1;

create table raena_analytics.reseller_base_recommendation_base_stage1_t3_v1
as
SELECT shipping_province,
             A.sku ,
             A.sku_name ,
             A.brand_name,
             A.category_name,
             A.product_type ,
             sum(total_quantity) total_quantity_sku,
             sum(DISTINCT B.Pre_discount_gm) Pre_discount_gm,
             in_stock
      FROM raena_analytics.SKU_base_recommendation_base_t3 A
      INNER JOIN raena_analytics.SKU_base_recommendation_base_v2 B ON A.sku= B.sku
      inner join raena_analytics.sku_in_stock C on A.sku=C.sku
      WHERE B.Pre_discount_gm>=10 and C.in_stock>10
      GROUP BY 1,
               2,
               3,
               4,
               5,
               6,9;

  drop table if exists raena_analytics.reseller_base_recommendation_base_stage1_t3_v2;

create table raena_analytics.reseller_base_recommendation_base_stage1_t3_v2
as
 SELECT A.reseller_id ,
          A.sku ,
          A.dropshipping_province,
          B.sku recommended_sku,
          B.sku_name AS recommended_sku_name,
          B.category_name AS recommended_category,
          B.product_type AS recommended_product,
          B.brand_name AS recommended_brand,
          B.shipping_province recommended_province,
          total_quantity_sku total_quantity_sku ,
          B.Pre_discount_gm
   FROM (select distinct  reseller_id ,
                sku,
                dropshipping_province
   from  raena_analytics.reseller_base_recommendation_base_stage1_t3
   where  dropshipping_province is not null ) A
   LEFT JOIN raena_analytics.reseller_base_recommendation_base_stage1_t3_v1 B
   ON A.dropshipping_province = B.shipping_province ;



DROP TABLE raena_analytics.same_province_with_diff_sku_dropshipping;



CREATE TABLE raena_analytics.same_province_with_diff_sku_dropshipping AS
select * from
(
SELECT *,row_number() over(partition by reseller_id ,sku,dropshipping_province
          ORDER BY Pre_discount_gm DESC) rnk
from raena_analytics.reseller_base_recommendation_base_stage1_t3_v2 A
 WHERE A.sku <> A.recommended_sku and dropshipping_province is not null ) AA
  where  rnk<11
ORDER BY sku ,
         rnk;

 ---------------
 DROP TABLE raena_analytics.recommendation_same_province_with_diff_sku_dropshipping;


CREATE TABLE raena_analytics.recommendation_same_province_with_diff_sku_dropshipping AS
SELECT DISTINCT B.email reseller_email,
                B.mobile reseller_mobile,
                sku ,
                dropshipping_province,
                recommended_sku,
                recommended_sku_name,
                recommended_category,
                recommended_product,
                recommended_brand,
                Pre_discount_gm,
                total_quantity_sku sales_factor,
                Pre_discount_gm*total_quantity_sku sorting
FROM raena_analytics.same_province_with_diff_sku_dropshipping A
INNER JOIN raena_user_management.user B ON A.reseller_id = cast(B.id as varchar)
WHERE Pre_discount_gm >=10;

drop table if exists raena_analytics.recommendation_same_province_with_diff_sku_dropshipping_v1;

create table raena_analytics.recommendation_same_province_with_diff_sku_dropshipping_v1
as
SELECT shipping_province,
             A.sku ,
             A.sku_name ,
             A.brand_name,
             A.category_name,
             A.product_type ,
             sum(total_quantity) total_quantity_sku,
             sum(DISTINCT B.Pre_discount_gm) Pre_discount_gm
      FROM raena_analytics.SKU_base_recommendation_base_t3 A
      INNER JOIN raena_analytics.SKU_base_recommendation_base_v2 B ON A.sku= B.sku
      inner join raena_analytics.sku_in_stock C on A.sku=C.sku
      WHERE B.Pre_discount_gm>=10 and C.in_stock>10
      GROUP BY 1,
               2,
               3,
               4,
               5,
               6;


DROP TABLE IF EXISTS raena_analytics.recommendation_same_province_with_diff_sku_dropshipping_v2;


CREATE TABLE raena_analytics.recommendation_same_province_with_diff_sku_dropshipping_v2 AS
SELECT A.reseller_id ,
       A.sku ,
       A.reseller_province,
       B.sku recommended_sku,
       B.sku_name AS recommended_sku_name,
       B.category_name AS recommended_category,
       B.product_type AS recommended_product,
       B.brand_name AS recommended_brand,
       B.shipping_province recommended_province,
       total_quantity_sku ,
        B.Pre_discount_gm
FROM raena_analytics.reseller_base_recommendation_base_stage1_t3 A
LEFT JOIN raena_analytics.recommendation_same_province_with_diff_sku_dropshipping_v1 B ON A.reseller_province = B.shipping_province
WHERE A.reseller_province IS NOT NULL;


DROP TABLE raena_analytics.same_province_with_diff_sku_reseller;


CREATE TABLE raena_analytics.same_province_with_diff_sku_reseller AS
select * from
(
SELECT *,row_number() over(partition by reseller_id ,sku,reseller_province
          ORDER BY Pre_discount_gm DESC) rnk
FROM  raena_analytics.recommendation_same_province_with_diff_sku_dropshipping_v2 A
WHERE A.sku <> A.recommended_sku and A.reseller_province  is not null ) AA
  where rnk<11
ORDER BY sku ,
         rnk;

----


DROP TABLE raena_analytics.recommendation_same_province_with_diff_sku_reseller;


CREATE TABLE raena_analytics.recommendation_same_province_with_diff_sku_reseller AS
SELECT DISTINCT B.email reseller_email,
                B.mobile reseller_mobile,
                sku ,
                reseller_province,
                recommended_sku,
                recommended_sku_name,
                recommended_category,
                recommended_product,
                recommended_brand,
                Pre_discount_gm,
                total_quantity_sku sales_factor,
                Pre_discount_gm*total_quantity_sku sorting
FROM raena_analytics.same_province_with_diff_sku_reseller A
INNER JOIN raena_user_management.user B ON A.reseller_id = cast(B.id as varchar)
WHERE Pre_discount_gm >=10;

drop table if exists raena_analytics.recommendation_same_province_with_diff_sku_reseller_v1;

create table raena_analytics.recommendation_same_province_with_diff_sku_reseller_v1
as
SELECT shipping_province,
             A.sku ,
             A.sku_name ,
             A.brand_name,
             A.category_name,
             A.product_type ,
             sum(total_quantity) total_quantity_sku,
             sum(DISTINCT B.Pre_discount_gm) Pre_discount_gm
      FROM raena_analytics.SKU_base_recommendation_base_t3 A
      INNER JOIN raena_analytics.SKU_base_recommendation_base_v2 B ON A.sku= B.sku
      inner join raena_analytics.sku_in_stock C on A.sku=C.sku
      WHERE B.Pre_discount_gm>=10 and C.in_stock>10
      GROUP BY 1,
               2,
               3,
               4,
               5,
               6;

DROP TABLE IF EXISTS raena_analytics.recommendation_same_province_with_diff_sku_reseller_v2;


CREATE TABLE raena_analytics.recommendation_same_province_with_diff_sku_reseller_v2 AS
SELECT A.reseller_id ,
       A.sku ,
       A.dropshipping_province,
       A.total_quantity,
       B.sku recommended_sku,
       B.sku_name AS recommended_sku_name,
       B.category_name AS recommended_category,
       B.product_type AS recommended_product,
       B.brand_name AS recommended_brand,
       B.shipping_province recommended_province,
       total_quantity_sku ,
       B.Pre_discount_gm
FROM raena_analytics.reseller_base_recommendation_base_stage1_t3 A
LEFT JOIN raena_analytics.recommendation_same_province_with_diff_sku_reseller_v1 B ON A.dropshipping_province = B.shipping_province
WHERE A.dropshipping_province IS NOT NULL;

DROP TABLE raena_analytics.same_province_with_same_sku_dropshipping;


CREATE TABLE raena_analytics.same_province_with_same_sku_dropshipping AS
SELECT *
FROM
  (SELECT *,
          total_quantity_sku/total_quantity sales_factor,
          row_number() over(partition BY reseller_id ,sku,dropshipping_province
                            ORDER BY Pre_discount_gm DESC) rnk
   FROM raena_analytics.recommendation_same_province_with_diff_sku_reseller_v2 A
   WHERE sku = recommended_sku
     AND A.dropshipping_province IS NOT NULL) AA
WHERE rnk<11
ORDER BY sku ,
         rnk;

DROP TABLE raena_analytics.recommendation_same_province_with_same_sku_dropshipping;


CREATE TABLE raena_analytics.recommendation_same_province_with_same_sku_dropshipping AS
SELECT DISTINCT B.email reseller_email,
                B.mobile reseller_mobile,
                sku ,
                dropshipping_province,
                recommended_sku,
                recommended_sku_name,
                recommended_category,
                recommended_product,
                recommended_brand,
                Pre_discount_gm,
                sales_factor,
                Pre_discount_gm*sales_factor sorting
FROM raena_analytics.same_province_with_same_sku_dropshipping A
INNER JOIN raena_user_management.user B ON A.reseller_id = cast(B.id as varchar)
WHERE Pre_discount_gm >=10;


drop table if exists raena_analytics.recommendation_same_province_with_same_sku_dropshipping_v1;

create table raena_analytics.recommendation_same_province_with_same_sku_dropshipping_v1
as
SELECT shipping_province,
             A.sku ,
             A.sku_name ,
             A.brand_name,
             A.category_name,
             A.product_type ,
             sum(total_quantity) total_quantity_sku,
             sum(DISTINCT B.Pre_discount_gm) Pre_discount_gm
      FROM raena_analytics.SKU_base_recommendation_base_t3 A
      INNER JOIN raena_analytics.SKU_base_recommendation_base_v2 B ON A.sku= B.sku
      inner join raena_analytics.sku_in_stock C on A.sku=C.sku
      WHERE B.Pre_discount_gm>=10 and C.in_stock>10
      GROUP BY 1,
               2,
               3,
               4,
               5,
               6;

drop table if exists raena_analytics.recommendation_same_province_with_same_sku_dropshipping_v2;

create table raena_analytics.recommendation_same_province_with_same_sku_dropshipping_v2
as
SELECT A.reseller_id ,
          A.sku ,
          A.reseller_province,
          A.total_quantity,
          B.sku recommended_sku,
          B.sku_name AS recommended_sku_name,
          B.category_name AS recommended_category,
          B.product_type AS recommended_product,
          B.brand_name AS recommended_brand,
          B.shipping_province recommended_province,
          total_quantity_sku ,
          B.Pre_discount_gm
   FROM raena_analytics.reseller_base_recommendation_base_stage1_t3 A
   LEFT JOIN raena_analytics.recommendation_same_province_with_same_sku_dropshipping_v1 B
   ON  A.reseller_province = B.shipping_province where A.reseller_province is not null ;


 DROP TABLE raena_analytics.same_province_with_same_sku_reseller;


CREATE TABLE raena_analytics.same_province_with_same_sku_reseller AS
select * from (
SELECT *,
       total_quantity_sku/total_quantity sales_factor,
       row_number() over(partition by reseller_id ,sku,reseller_province
          ORDER BY Pre_discount_gm DESC) rnk
FROM raena_analytics.recommendation_same_province_with_same_sku_dropshipping_v2 A
WHERE sku = recommended_sku and A.reseller_province is not null )AA
  where  rnk<11
ORDER BY sku ,
         rnk;

 DROP TABLE raena_analytics.recommendation_same_province_with_same_sku_reseller;


CREATE TABLE raena_analytics.recommendation_same_province_with_same_sku_reseller AS
SELECT DISTINCT B.email reseller_email,
                B.mobile reseller_mobile,
                sku ,
                reseller_province,
                recommended_sku,
                recommended_sku_name,
                recommended_category,
                recommended_product,
                recommended_brand,
                Pre_discount_gm,
                sales_factor,
                Pre_discount_gm*sales_factor sorting
FROM raena_analytics.same_province_with_same_sku_reseller A
INNER JOIN raena_user_management.user B ON A.reseller_id = cast(B.id as varchar)
WHERE Pre_discount_gm >=10;



