sql - Excel Pivot: pivot two columns in table without summarizing values -
i'm using query in excel following table:
select "work_center"."eqno", "ud_data"."ud_cols_id", "work_center"."cuser1", "work_center"."cuser2", "work_center"."cuser3", "work_center"."cuser4", "work_center"."cuser5", "work_center"."nuser1", "work_center"."nuser2", "work_center"."nuser3", "work_center"."nuser4", "work_center"."nuser5", "ud_data"."cuser" "iqms"."ud_data" "ud_data" full outer join "iqms"."work_center" "work_center" on "ud_data"."parent_id"="work_center"."id" "work_center"."mfg_type"='injection' , "ud_data"."ud_cols_id" not null order "work_center"."eqno"
result
which has duplicates apart ud_cols_id(16,17,16,17...) , cuser(1000,test1,2000,test2.....)
desired result
but i've been trying in excel pivot column ud_cols_id on cuser(the last column in previous image) column, remove duplicate lines ,
i've tried using excels pivot table can't seem prevent summarizing values e.g have ud_cols_id column headings, eqno , cuser values. keeps summarizing value field , there doesn't seem way not choose that?
searching fixes keeps leading me examples want summarize data. , adding more values row , columns makes harder follow.
how should go doing this?
you're looking more this:
select work_center.eqno, work_center.cuser1, work_center.cuser2, work_center.cuser3, work_center.cuser4, work_center.cuser5, work_center.nuser1, work_center.nuser2, work_center.nuser3, work_center.nuser4, work_center.nuser5, ud_data_id_16.cuser id_16, ud_data_id_17.cuser id_17 iqms.work_center work_center inner join iqms.ud_data ud_data_id_16 on work_center.id=ud_data_id_16.parent_id , ud_data_id_16.ud_cols_id = 16 inner join iqms.ud_data ud_data_id_17 on work_center.id=ud_data_id_17.parent_id , ud_data_id_17.ud_cols_id = 17 work_center.mfg_type='injection' order work_center.eqno
why? well, ud_data has 2 rows per every work_center row, don't want both rows each associating every work_center row because double work_center rows. called cartesian product. gets worse if there x rows in work_center y rows in ud_data, number of duplicates becomes x * y
what need convert multiple rows per "thing" in ud_data single rows. either pivoting data in oracle, or joining table multiple times, , specifying reduces relationship 1:1 between ud_data , work_center.
a work_center row simplified column layout:
id, ud_data_id wc1, ud1 wc2, ud2 wc3, ud3
a ud_data row set:
id, thing, otherthing ud1, apple, 100 ud1, android, 101 ud2, apple, hello ud2, android, goodbye ud3, apple, jan-17 ud3, android, dec-25
the 2 ud rows per work centre row need become 1 row. either before join once, pivoting ud data rows this:
id, applething, androidthing ud1, 100, 101 ud2, hello, goodbye ud3, jan-17, dec25
or join twice, selecting youre interested in each time (not syntactically correct regard id - no db accept this, that's not point being made):
work_center join ud_data on id=id , ud_data.thing='apple' join ud_data on id=id , ud_data.thing='android'
Comments
Post a Comment