I have a very disorganized table from a legacy system. It looks like this:
ID | ProjArea | Task | SumDays | AI | SDLC | DEV | PT | CS | ENG |
-------------------------------------------------------------------
239 | A | SDLC | 2 | | 2 | | | | |
239 | A | DEV | 3 | | | 3 | | | |
239 | A | AI | 8 | 8 | | | | | |
239 | A | PT | 2 | | | | 2 | | |
239 | B | DEV | 4 | | | 4 | | | |
239 | B | AI | 2 | 2 | | | | | |
239 | B | PT | 2 | | | | 2 | | |
71 | B | DEV | 5 | | | 5 | | | |
71 | B | AI | 2 | 2 | | | | | |
71 | A | PT | 2 | | | | 2 | | |
From the table above, we can see that it is very redundant having the task as a column and a task column. I am designing a query that merges the data in one column instead of multiple for each project Area.
Expected End result looks like this:
ID | ProjArea | SumDays | AI | SDLC | DEV | PT | CS | ENG |
-------------------------------------------------------------------
239 | A | 15 | 8 | 2 | 3 | 2 | | |
239 | B | 8 | 2 | | 4 | 2 | | |
71 | A | 2 | | | | 2 | | |
71 | B | 7 | 2 | | 5 | | | |
I have tried a full outer join on the table itself and still havent been able to achieve this. Any ideas or hint on how to achieve this? I am writing VBA code to attempt this too.
I think you can get what you want with an aggregation query:
select id, projarea, sum(sumdays) as sumdays,
sum(ai) as ai, sum(sdlc) as sdlc, sum(dev) as dev, sum(pt) as pt,
sum(cs) as cs, sum(eng) as eng
from t
group by id, projarea;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.