Jump to content

SQL Join help


Metorph

Recommended Posts

Hey,

I have an SQL exercise, and i have no idea how to solve this.

I have 2 tables.

The first table has 1 record for simplicity and 3 columns (ID, A, B). Like this:

 Row Number         ID          A             B

1                               XY         100          10

 

The second table has 3 record and 3 columns (ID, a1, Data):

 Row Number         ID          a1             Date

1                               XY         30          2018.12.31

2                               XY         30          2019.03.31

3                               XY         30          2019.06.30

My task to get this table:

 Row Number         ID            A              B                     a1             Date

1                               XY            0              10                  30          2018.12.31

2                               XY            0               0                   30          2019.03.31

3                               XY            90             0                   30          2019.06.30

"A" field has to be 0, except the latest line by date, which has to be the sum of "a1" (3*30).

"B" field has to be 0, except the first line by date, which has to be equal "B" from the first table (10).

 

Thanks for your support and help. :)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...