SQL 3 IDs Change Over Time












0














I have a logic question which I've been stuck on for a while.



Suppose there is one customer that can be serviced in two separate places, for place A they receive A_ID and place B they receive B_ID. There is a 3rd ID which I will call C_ID which links the two customers together to give a holistic view if they are on both platforms. The customers can be buying from place A only, place B only, or place A and B at the same time.



I want to create a volatile table to back fill populating with A_ID, B_ID, C_ID, on all days if if they are not null.



Currently the data can look like any of the following in the same table:



EXAMPLE A 
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , 145 , ,
02/01/17 , 145 , ,
03/01/17 , 145 , 201501 , 601888
04/01/17 , 145 , 201502 , 601888
05/01/17 , 145 , 201502 , 601888


OR



EXAMPLE B
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , 198 , ,
02/01/17 , 198 , ,
03/01/17 , 198 , ,
04/01/17 , 198 , ,
05/01/17 , 198 , ,


OR



EXAMPLE C
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , , 567222 ,
02/01/17 , , 567222 ,
03/01/17 , , 567222 ,
04/01/17 , , 567222 ,
05/01/17 , , 567222 ,


I tried a window function:



SELECT 
calendar_date,
MAX(A_ID) OVER(PARTITION BY C_ID) A_ID,
MAX(B_ID) OVER(PARTITION BY C_ID) B_ID,
MAX(C_ID) OVER(PARTITION BY B_ID,A_ID) C_ID,
FROM TABLE A


However this removes all examples which have not yet used both platforms, i.e. example B and example C will not show.



Any ideas?










share|improve this question
























  • Hi, and welcome to Stack Overflow. What is the purpose of back filling the data? Is it just to ensure you have all their IDs available in every row?
    – Schwern
    Nov 16 '18 at 16:54










  • There are scripts that run a lookback view at each customer later in the process for customer segmentation and analysis - without consistent IDs for each customer in all months previous erroneous results are produced
    – flippinart
    Nov 16 '18 at 17:08










  • So yes - just to be clear, I want all "their" IDs to show in everyone. I.E. if a customer has B_ID NOT NULL in the future but NULL in the past, I want that NOT NULL value to show in the past. And thank you!
    – flippinart
    Nov 16 '18 at 17:21










  • What result do you expect when there's no id for a place, e.g. B_ID and C_ID in example B?
    – dnoeth
    Nov 16 '18 at 20:14










  • Hi @dnoeth thanks for your input - I would expect NULL.
    – flippinart
    Nov 19 '18 at 10:23
















0














I have a logic question which I've been stuck on for a while.



Suppose there is one customer that can be serviced in two separate places, for place A they receive A_ID and place B they receive B_ID. There is a 3rd ID which I will call C_ID which links the two customers together to give a holistic view if they are on both platforms. The customers can be buying from place A only, place B only, or place A and B at the same time.



I want to create a volatile table to back fill populating with A_ID, B_ID, C_ID, on all days if if they are not null.



Currently the data can look like any of the following in the same table:



EXAMPLE A 
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , 145 , ,
02/01/17 , 145 , ,
03/01/17 , 145 , 201501 , 601888
04/01/17 , 145 , 201502 , 601888
05/01/17 , 145 , 201502 , 601888


OR



EXAMPLE B
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , 198 , ,
02/01/17 , 198 , ,
03/01/17 , 198 , ,
04/01/17 , 198 , ,
05/01/17 , 198 , ,


OR



EXAMPLE C
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , , 567222 ,
02/01/17 , , 567222 ,
03/01/17 , , 567222 ,
04/01/17 , , 567222 ,
05/01/17 , , 567222 ,


I tried a window function:



SELECT 
calendar_date,
MAX(A_ID) OVER(PARTITION BY C_ID) A_ID,
MAX(B_ID) OVER(PARTITION BY C_ID) B_ID,
MAX(C_ID) OVER(PARTITION BY B_ID,A_ID) C_ID,
FROM TABLE A


However this removes all examples which have not yet used both platforms, i.e. example B and example C will not show.



Any ideas?










share|improve this question
























  • Hi, and welcome to Stack Overflow. What is the purpose of back filling the data? Is it just to ensure you have all their IDs available in every row?
    – Schwern
    Nov 16 '18 at 16:54










  • There are scripts that run a lookback view at each customer later in the process for customer segmentation and analysis - without consistent IDs for each customer in all months previous erroneous results are produced
    – flippinart
    Nov 16 '18 at 17:08










  • So yes - just to be clear, I want all "their" IDs to show in everyone. I.E. if a customer has B_ID NOT NULL in the future but NULL in the past, I want that NOT NULL value to show in the past. And thank you!
    – flippinart
    Nov 16 '18 at 17:21










  • What result do you expect when there's no id for a place, e.g. B_ID and C_ID in example B?
    – dnoeth
    Nov 16 '18 at 20:14










  • Hi @dnoeth thanks for your input - I would expect NULL.
    – flippinart
    Nov 19 '18 at 10:23














0












0








0







I have a logic question which I've been stuck on for a while.



Suppose there is one customer that can be serviced in two separate places, for place A they receive A_ID and place B they receive B_ID. There is a 3rd ID which I will call C_ID which links the two customers together to give a holistic view if they are on both platforms. The customers can be buying from place A only, place B only, or place A and B at the same time.



I want to create a volatile table to back fill populating with A_ID, B_ID, C_ID, on all days if if they are not null.



Currently the data can look like any of the following in the same table:



EXAMPLE A 
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , 145 , ,
02/01/17 , 145 , ,
03/01/17 , 145 , 201501 , 601888
04/01/17 , 145 , 201502 , 601888
05/01/17 , 145 , 201502 , 601888


OR



EXAMPLE B
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , 198 , ,
02/01/17 , 198 , ,
03/01/17 , 198 , ,
04/01/17 , 198 , ,
05/01/17 , 198 , ,


OR



EXAMPLE C
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , , 567222 ,
02/01/17 , , 567222 ,
03/01/17 , , 567222 ,
04/01/17 , , 567222 ,
05/01/17 , , 567222 ,


I tried a window function:



SELECT 
calendar_date,
MAX(A_ID) OVER(PARTITION BY C_ID) A_ID,
MAX(B_ID) OVER(PARTITION BY C_ID) B_ID,
MAX(C_ID) OVER(PARTITION BY B_ID,A_ID) C_ID,
FROM TABLE A


However this removes all examples which have not yet used both platforms, i.e. example B and example C will not show.



Any ideas?










share|improve this question















I have a logic question which I've been stuck on for a while.



Suppose there is one customer that can be serviced in two separate places, for place A they receive A_ID and place B they receive B_ID. There is a 3rd ID which I will call C_ID which links the two customers together to give a holistic view if they are on both platforms. The customers can be buying from place A only, place B only, or place A and B at the same time.



I want to create a volatile table to back fill populating with A_ID, B_ID, C_ID, on all days if if they are not null.



Currently the data can look like any of the following in the same table:



EXAMPLE A 
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , 145 , ,
02/01/17 , 145 , ,
03/01/17 , 145 , 201501 , 601888
04/01/17 , 145 , 201502 , 601888
05/01/17 , 145 , 201502 , 601888


OR



EXAMPLE B
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , 198 , ,
02/01/17 , 198 , ,
03/01/17 , 198 , ,
04/01/17 , 198 , ,
05/01/17 , 198 , ,


OR



EXAMPLE C
Date , A_ID , B_ID , C_ID
---------------------------------------------
01/01/17 , , 567222 ,
02/01/17 , , 567222 ,
03/01/17 , , 567222 ,
04/01/17 , , 567222 ,
05/01/17 , , 567222 ,


I tried a window function:



SELECT 
calendar_date,
MAX(A_ID) OVER(PARTITION BY C_ID) A_ID,
MAX(B_ID) OVER(PARTITION BY C_ID) B_ID,
MAX(C_ID) OVER(PARTITION BY B_ID,A_ID) C_ID,
FROM TABLE A


However this removes all examples which have not yet used both platforms, i.e. example B and example C will not show.



Any ideas?







sql teradata






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 16:54









Mihai Chelaru

2,14291022




2,14291022










asked Nov 16 '18 at 16:40









flippinart

1




1












  • Hi, and welcome to Stack Overflow. What is the purpose of back filling the data? Is it just to ensure you have all their IDs available in every row?
    – Schwern
    Nov 16 '18 at 16:54










  • There are scripts that run a lookback view at each customer later in the process for customer segmentation and analysis - without consistent IDs for each customer in all months previous erroneous results are produced
    – flippinart
    Nov 16 '18 at 17:08










  • So yes - just to be clear, I want all "their" IDs to show in everyone. I.E. if a customer has B_ID NOT NULL in the future but NULL in the past, I want that NOT NULL value to show in the past. And thank you!
    – flippinart
    Nov 16 '18 at 17:21










  • What result do you expect when there's no id for a place, e.g. B_ID and C_ID in example B?
    – dnoeth
    Nov 16 '18 at 20:14










  • Hi @dnoeth thanks for your input - I would expect NULL.
    – flippinart
    Nov 19 '18 at 10:23


















  • Hi, and welcome to Stack Overflow. What is the purpose of back filling the data? Is it just to ensure you have all their IDs available in every row?
    – Schwern
    Nov 16 '18 at 16:54










  • There are scripts that run a lookback view at each customer later in the process for customer segmentation and analysis - without consistent IDs for each customer in all months previous erroneous results are produced
    – flippinart
    Nov 16 '18 at 17:08










  • So yes - just to be clear, I want all "their" IDs to show in everyone. I.E. if a customer has B_ID NOT NULL in the future but NULL in the past, I want that NOT NULL value to show in the past. And thank you!
    – flippinart
    Nov 16 '18 at 17:21










  • What result do you expect when there's no id for a place, e.g. B_ID and C_ID in example B?
    – dnoeth
    Nov 16 '18 at 20:14










  • Hi @dnoeth thanks for your input - I would expect NULL.
    – flippinart
    Nov 19 '18 at 10:23
















Hi, and welcome to Stack Overflow. What is the purpose of back filling the data? Is it just to ensure you have all their IDs available in every row?
– Schwern
Nov 16 '18 at 16:54




Hi, and welcome to Stack Overflow. What is the purpose of back filling the data? Is it just to ensure you have all their IDs available in every row?
– Schwern
Nov 16 '18 at 16:54












There are scripts that run a lookback view at each customer later in the process for customer segmentation and analysis - without consistent IDs for each customer in all months previous erroneous results are produced
– flippinart
Nov 16 '18 at 17:08




There are scripts that run a lookback view at each customer later in the process for customer segmentation and analysis - without consistent IDs for each customer in all months previous erroneous results are produced
– flippinart
Nov 16 '18 at 17:08












So yes - just to be clear, I want all "their" IDs to show in everyone. I.E. if a customer has B_ID NOT NULL in the future but NULL in the past, I want that NOT NULL value to show in the past. And thank you!
– flippinart
Nov 16 '18 at 17:21




So yes - just to be clear, I want all "their" IDs to show in everyone. I.E. if a customer has B_ID NOT NULL in the future but NULL in the past, I want that NOT NULL value to show in the past. And thank you!
– flippinart
Nov 16 '18 at 17:21












What result do you expect when there's no id for a place, e.g. B_ID and C_ID in example B?
– dnoeth
Nov 16 '18 at 20:14




What result do you expect when there's no id for a place, e.g. B_ID and C_ID in example B?
– dnoeth
Nov 16 '18 at 20:14












Hi @dnoeth thanks for your input - I would expect NULL.
– flippinart
Nov 19 '18 at 10:23




Hi @dnoeth thanks for your input - I would expect NULL.
– flippinart
Nov 19 '18 at 10:23

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53342063%2fsql-3-ids-change-over-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53342063%2fsql-3-ids-change-over-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?