2
I have 2 tables, a call SR7010
and another call SR3010
. The primary key of the two is the field R7_MAT and R3_MAT.
The query I’m trying to execute is this:
SELECT R7_FILIAL, R7_MAT, R7_DESCFUN, R7_DATA, R3_VALOR FROM SR7010 AS sr7
INNER JOIN SR3010 AS sr3 ON (sr3.R3_MAT = sr7.R7_MAT)
WHERE sr7.R7_MAT = 997
What happens is this: the field R3_VALOR appears with the repeated data, but the other fields (starting with R7) appear normally, and when the field R3_VALOR
changes, the data of the fields R7 are repeated, thus successively.
How to make it correctly bring the information, that is, only 3 lines, as below?
Are records of salary changes/position.
Ex: In the 1st line, with the position of Computer Assist, on the date of 20151029, is with the salary 50,00.
On the date of 20151115, still as computer Assist, salary was changed to 55,00.
On the date of 20151126, the position changed to Anal. de informatica, with the salary of 60,00.
What happens is that the data is being listed 3 times (amount of records of actually existing changes), but the value field, because it is another table, maybe, is displaying the same value 3 times to then change to another value and repeat again 3 times (number of changes records), and so on.
When I do a table search SR7010 across the countryside R7_MAT = 997, the database returns me 3 records. The same occurs when I do a search in the table SR3010 across the countryside R3_MAT = 997. It also returns 3 records, so I’m finding it strange.
If the date and value fields are not relevant, you can take them out of the query and give a group by R7_DESCFUN
– gmsantos
The problem is that the 5 fields are very relevant
– Thiago Alessandro
Wouldn’t it be a case of adding the value field? the ratio is 1-N?
– Marco Souza
What you could do is use the pivot command to turn rows into columns and have a column for each post.
– Jeferson Leonardo
Your second picture of the data makes no sense. for example ASSIST.INFORMATICA on day (R7_DATA) 20151029 has 3 different values on that day and you selected the smallest already on day 20151015 you took the middle one. ANAL. OF INFOR you got the most value, there’s not much logic in it. In place of the image post the data so it would help to understand and simulate easier.
– Marco Souza
Look like salary changes. R7_DESCFUN as the position, R7_DATA as the date of salary/position change and R7_VALOR as salary
– Thiago Alessandro
Ta very strange his salary change. the guy has 3 increase in the day and on another date has the increase of the same value?
– Marco Souza
This is exactly my problem. The correct should be according to the second image.
– Thiago Alessandro
Shouldn’t it be day 20151029 = 50 and day 20151115 = 60? the first two lines ?
– Marco Souza