Jump to content
Sign in to follow this  
Metorph

SQL Join help

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. :)

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...