Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
berryandcherry6
Creator II
Creator II

Loading table with appending extra column and Applying Condition

Hi,

Assume i have a data like below

  

Batch_idCampaign_idCampaign_name
5552camp_bc
5553camp_cd
5551camp_ab
5662camp_bc
5771camp_ab
5554camp_ef
5881camp_ab
5661camp_ab
5491camp_ab
5722camp_bc

I want to create a script to order batch_id in Ascending , campaign_id  in Descending, and to create a one more column called brand_name with  latest  campaign_id with brand_1, second latest as brand_2 etc.. as shown in below figure

   

Batch_idCampaign_idCampaign_namebrand_name
5491camp_abbrand_1
5554camp_efbrand_4
5553camp_cdbrand_3
5552camp_bcbrand_2
5551camp_abbrand_1
5662camp_bcbrand_2
5661camp_abbrand_1
5772camp_bcbrand_2
5771camp_abbrand_1
5881camp_abbrand_1

I have below code currently

let varExpirationDate  = Timestamp(Today(),'YYYY-MM-DD hh:mm:ss');

LOAD `campaign_id`,

     `campaign_group_id`,

     `batch_meta_data_id`,

     `start_date` as Campaign_Start_Date,

      date(floor(expiration_date),'MM-DD-YYYY') as expiration_date,

     `campaign_name` where expiration_date >= '$(varExpirationDate)';

SQL SELECT `campaign_id`,

     `start_date`,

     `batch_meta_data_id`,

     `campaign_group_id`,

     `campaign_name`,

      expiration_date

FROM CAMPAIGN where batch_meta_data_id IN ('54','55','56','57','58') Order by campaign_id desc;

1 Solution

Accepted Solutions
sunny_talwar

May be this:

let varExpirationDate  = Timestamp(Today(),'YYYY-MM-DD hh:mm:ss');

Table:

LOAD `campaign_id`,

    `campaign_group_id`,

    `batch_meta_data_id`,

    `start_date` as Campaign_Start_Date,

      date(floor(expiration_date),'MM-DD-YYYY') as expiration_date,

    `campaign_name` where expiration_date >= '$(varExpirationDate)';

SQL SELECT `campaign_id`,

    `start_date`,

    `batch_meta_data_id`,

    `campaign_group_id`,

    `campaign_name`,

      expiration_date

FROM CAMPAIGN where batch_meta_data_id IN ('54','55','56','57','58') Order by campaign_id desc;

FinalTable:

LOAD *,

    'brand_' & AutoNumber(Campaign_id, batch_meta_data_id) as brand_name

Resident Table

Order By batch_meta_data_id, Campaign_id;

DROP Table Table;

View solution in original post

8 Replies
sunny_talwar

May be this:

let varExpirationDate  = Timestamp(Today(),'YYYY-MM-DD hh:mm:ss');

Table:

LOAD `campaign_id`,

    `campaign_group_id`,

    `batch_meta_data_id`,

    `start_date` as Campaign_Start_Date,

      date(floor(expiration_date),'MM-DD-YYYY') as expiration_date,

    `campaign_name` where expiration_date >= '$(varExpirationDate)';

SQL SELECT `campaign_id`,

    `start_date`,

    `batch_meta_data_id`,

    `campaign_group_id`,

    `campaign_name`,

      expiration_date

FROM CAMPAIGN where batch_meta_data_id IN ('54','55','56','57','58') Order by campaign_id desc;

FinalTable:

LOAD *,

    'brand_' & AutoNumber(Campaign_id, batch_meta_data_id) as brand_name

Resident Table

Order By batch_meta_data_id, Campaign_id;

DROP Table Table;

berryandcherry6
Creator II
Creator II
Author

Hi Sunny,

i am getting sync error.

Synerror.PNG

sunny_talwar

Did you forget to drop the Table?

Capture.PNG

berryandcherry6
Creator II
Creator II
Author

Thanks Sunny, that was quick needed response.

berryandcherry6
Creator II
Creator II
Author

Hi Sunny,

one more thing,

Here instead of batch_1, batch 2 ...., i need to keep it as current week, latest week, second latest week.

How could i do that. But it has to be different words for diferent brand_name

sunny_talwar

Can you explain by amending your above example?

berryandcherry6
Creator II
Creator II
Author

Because in our services, we usually show data for campaigns. Some times these campaigns will be running for 1 week, 2 week, 3 week ...  so at this time i need to display them whether they are Current Week, Previous Week or Last Week.

sunny_talwar

That's not what I asked for.... You shared this in your initial post

Capture.PNG

I guess you want to change brand_name to something else now? Is that right?