The original table:
=======================================================================================
| A | B | C | D | E | F | G |
=======================================================================================
| 65432 | AFD452E | sometext1 | IA1 | 10,6 | 8,5 | 22,0 |
| 65432 | AFD452E | sometext1 | IA2 | | 11,4 | 16,5 |
| 65432 | AFD452E | sometext1 | IA3 | | 3,5 | 5,3 |
| 65989 | 74652E | sometext2 | IA1 | 3,3 | | 8 |
| 65989 | 74652E | sometext2 | IA3 | 23 | 1,1 | 6,9 |
| 27890 | P8965A | sometext3 | IA3 | 12,7 | 13,8 | 33,2 |
| 34432 | P673452 | sometext6 | IA6 | | | |
| 55770 | 27799A | sometext7 | IA7 | | | |
=======================================================================================
The resulting table should be:
=======================================================================================
| A | B | C | NEWA1 | NEWA2 | NEWA3 |
=======================================================================================
| 65432 | AFD452E | sometext1 | 10,6-8,5-22,0-| -11,4-16,5- | |
| 65989 | 74652E | sometext2 | 3,3--8- | | 23-1,1-6,9- |
| 27890 | P8965A | sometext3 | | | 12,7-13,8-33,2- |
=======================================================================================
This is what I got so far :
SELECT A, B, C,
max(iif([D] like "IA1" .. rest of code)) as newa1,
max(iif([D] like "IA2" .. rest of code)) as newa2,
max(iif([D] like "IA3" .. rest of code)) as newa3
from table
group by A, B,C;
This is the output of that query :
=======================================================================================
| A | B | C | NEWA1 | NEWA2 | NEWA3 |
=======================================================================================
| 65432 | AFD452E | sometext1 | 10,6-8,5-22,0-| -11,4-16,5- | |
| 65989 | 74652E | sometext2 | 3,3--8- | | 23-1,1-6,9- |
| 27890 | P8965A | sometext3 | | | 12,7-13,8-33,2- |
| 34432 | P673452 | sometext6 | | | |
| 55770 | 27799A | sometext7 | | | |
=======================================================================================
NEWxx
values in your expected output looked slightly differently. E.g. the second row'sNEWA1
was to be3,3-8
but in the new version it became3,3--8-
– same as your actual output, in fact. Could you please clarify/edit what they should really be? Note also an emptyNEWA3
in the text version where it previously was3,5-5,3
. I'm guessing that's a mistake, because it matched the source before but now it doesn't. (Your actual output likely has a mistake too: it shows the same value inNEWA2
andNEWA3
for65432 | AFD452E | sometext1
.)A, B, C
and you do not seem to be selecting D in your SELECT clause – how then can you getIA6
,IA7
etc. in the output? That exact GROUP BY and MAXes around your IIFs were what I was going to suggest too, by the way. (I just wanted to clarify that thing I asked 2 hours ago before posting my answer.) So I really don't understand your problem at this point. You may have done something wrong but I can't figure out what it could be. Maybe you should update your question now that you seem to have found a solution but are struggling to implement it.