0
I need to create a filter in SQL that follows some rules, I have a spreadsheet in Excel and in it I need to apply the following filter, the spreadsheet has the fields:
- GSM
- MOTIVO_ENVIO
- DATA_ATIVACAO
- DATA_IMPORTACAO
- DATA_ALTERACAO
- STATUS
Filter:
GSM which repeats itself and has the STATUS = "PENDING", "UNDER REVIEW" but its MOTIVO_ENVIO is different, only import the line that has the STATUS equal to "TEMPORARY MALFUNCTION"
I tried in many ways, but unsuccessfully, I don’t have as much knowledge with Database and so I would like your help, as far as I got was:
SELECT [GSM],
[MOTIVO_ENVIO],
[DATA_ATIVACAO],
[DATA_IMPORTACAO],
[DATA_ALTERACAO],
[STATUS]
FROM [export$] AS export
WHERE EXISTS
(SELECT aux.[GSM]
FROM [export$] AS aux
WHERE export.[GSM] = aux.[GSM]
AND [STATUS] = "PENDENTE")
AND [STATUS] = "ANOMALIA TEMPORÁRIA"
But I couldn’t place one of the most important parts of the filter:
...your MOTIVO_ENVIO is different, only import the line that has the STATUS equal to "TEMPORARY MALFUNCTION"
The below follows an example of how would be the structure that is found in the spreadsheet, just apply the filter now so that I can extract the "TEMPORARY ANOMALY" according to the rules mentioned.
I would love to help you, I thank you in advance!
Share table with some data, can be in Pastebin in sharecsv ...
– thiaguerd
@thiaguerd of course, here it is complete: https://drive.google.com/file/d/1wXHhvI9In4j_lrwB3dzcyHsm5jThlkcQ/view
– Magno
I changed the column names, the changes were: Nº Tel = GSM | Sending Reason = MOTIVO_ENVIO | Activation Date = DATA_ATIVACAO | Import Date = DATA_IMPORTACAO | Change Date = DATA_ALTERACAO | Status = STATUS | I will edit the post to leave everything straight :)
– Magno
Paste this spreadsheet into table format for me to play your scenario and try to help.
– Ismael
@Ismael https://drive.google.com/open?id=1S1KKp6qKw1nykDK4nZRWO0O4CzZRxAS0
– thiaguerd
I don’t have access :( the company restricts, so I have some limitations... The question would need to be edited.
– Ismael