Table Name: Records
| ID | Date | Time | Status | BoxType | Material | Rack | EmployeeNr | Transaction |
|---|---|---|---|---|---|---|---|---|
| 1 | 25-05-2020 | 13:11:12 | 70 | 36757 | 4 | 4 | 188 | 2 |
| 2 | 25-05-2020 | 13:12:40 | 71 | 31178 | 2 | 5 | 188 | 2 |
| 3 | 25-05-2020 | 13:13:31 | 71 | 31178 | 2 | 5 | 188 | 102 |
| 4 | 27-05-2020 | 13:14:14 | 71 | 38444 | 3 | 2 | 181 | 3 |
| 5 | 27-05-2020 | 13:14:15 | 71 | 38444 | 3 | 2 | 181 | 3 |
| 6 | 27-05-2020 | 13:14:41 | 71 | 38444 | 3 | 2 | 181 | 3 |
| 7 | 27-05-2020 | 13:15:10 | 71 | 39123 | 6 | 5 | 188 | 3 |
| 8 | 27-05-2020 | 13:15:51 | 71 | 38444 | 3 | 2 | 181 | 103 |
| 9 | 27-05-2020 | 13:16:51 | 71 | 38444 | 3 | 2 | 181 | 103 |
The Desired OUTPUT I want is Rows 1, 6 and 7
| ID | Date | Time | Status | BoxType | Material | Rack | EmployeeNr | Transaction |
|---|---|---|---|---|---|---|---|---|
| 1 | 25-05-2020 | 13:11:12 | 70 | 36757 | 4 | 4 | 188 | 2 |
| 6 | 27-05-2020 | 13:14:41 | 71 | 38444 | 3 | 2 | 181 | 3 |
| 7 | 27-05-2020 | 13:15:10 | 71 | 39123 | 6 | 5 | 188 | 3 |
Hello dear developer friends,
I have this table "Records". There are two types of transaction viz. 'Forward' and 'Reverse'. The Forward transactions are represented by single to two digits of numbers (that is from 1 to 30) and Reverse transactions are represented by three digits (that is from 100 to 130). Now, every unique Forward transaction has a unique reverse transaction. (For eg. Transaction 1 will have 101, transaction 2 will have 102 and transaction 3 will have 103 and so on).
I do not want to see the Reverse transactions and as well as their forward transactions in my report. (For eg. 102 and 2, 103 and 3) But, I have to find the matching forward transactions whose other columns data (Date, Status,BoxType, Material, Rack,EmployeeNr) are same of Reverse transaction. (As seen in the image, record no. 2 and 3) Also, there can be more than one matches of forward transactions for reverse transactions, and I want to skip only those many forward transactions equal to number of Reverse transactions. (*As seen in the table, record no. 4,5 and 6 matches to record no. 8 and 9, so I want to hide two records no. 4 and 5 with 8 and 9)
So, I tried to write a SQL query, but it is not working in MS access. Appreciate your great help! Thank you! Best Regards.
My code
with table_a as (
select a.*, row_number() over (partitition by Status, BoxType, Material, Rack, EmployeeNr , Transaction) as dup_n --all columns except ID and time.
---for multiple entries of same type
from Records a
where Transaction<100
)
,table_b as (
select b.*, (Transaction-100) as type_new,
row_number() over (partitition by Status, BoxType, Material, Rack, EmployeeNr , Transaction) as dup_n --all columns except time and ID
---for multiple entries of same type
from Records b
where Transaction>99
)
select*from(
select a.* from table_a
left join table_b
on <Status, BoxType, Material, Rack, EmployeeNr , Transaction> --all columns except time and ID
and a.type = b.type_new
and a.dup_n = b.dup_n
)
where a.Transaction is null