1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Create column based on other column but with conditions

Discussão em 'Outras Linguagens' iniciado por Stack, Janeiro 27, 2021.

  1. Stack

    Stack Membro Participativo

    I'm very new to SQL and I've I simply cannot work out a method for the following:

    I have this table with start dates of the codes

    Row Code Start Date Product
    1 A1 2020-01-01 X
    2 A1 2020-05-15 Y
    3 A2 2020-02-02 X
    4 A3 2020-01-31 Z
    5 A3 2020-02-15 Y
    6 A3 2020-12-31 X


    Ultimately I need to be able to query another table and find out what Product a code was on a certain date, so Code A1 on 2020-01-10 was = X, but Code A1 today is = Y

    I think I can work out how to use a between statement in the where clause, but I cannot work out how to Alter the table to have an End Date so it looks like this:

    Row Code Start_Date Product End_Date
    1 A1 2020-01-01 X 2020-05-14
    2 A1 2020-05-15 Y NULL
    3 A2 2020-02-02 X NULL
    4 A3 2020-01-31 Z 2020-02-14
    5 A3 2020-02-15 Y 2020-12-30
    6 A3 2020-12-31 X NULL


    Please note the database does not have an End_Date field

    Continue reading...

Compartilhe esta Página