SQL queries - two tables (excel spreadsheets) consolidated [closed]

0

Hello. I have a question, which I think is simple for the veterans of the forum. I do not have much SQL notion, but I need to integrate two files into excel One stock and one sales

There are two different xls. Both have a BD (tab) called "General Base."

I have columns for branding, product, month, year, and values ... where:

In the stock worksheet, my value field is called STOCK and in sales, SALES

I need to create a third spreadsheet that consolidates the two via Query, where I will take the (MARK / PRODUCT / YEAR / MONTH) columns of the two and I will take STOCK and SALES as well as create a third column .. In this third column, called "OUTPUT STOCK", the formula is as follows:

SAIDA ESTOQUE = Estoque do mês anterior* + venda - estoque do mês atual

In this way, in the previous month's inventory, you would need to do a prov or somase, pulling the value from the previous month ... for example. if I bring a line that has February, it should bring (STOCK JANUARY + February sales - February Stock)

If someone helps me solve it, I thank you immensely. PS: I already used union in sql, but I packed the columns with different names

[! [image 1 - stock base] [1]] [1]

[! [image 2 - sales base] [2]] [2]

Unfortunately, I can not insert all images

    
asked by anonymous 31.08.2017 / 21:08

1 answer

1

You can do this as follows:

Step 1: Create Query for File 1 (Image 1)

Step 2: Create query for file 2 (Image 1)

Step 3: Create a new query From the "Merge Queries" menu > "Start Query Editor" (Image 2)

Step 4: Maintain the desired columns of each query, if necessary, you can right-click to rename the columns.

    
31.08.2017 / 21:24