mysql - Need to convert a table rows to column in another table based on Table 1 elements condition -
i have 2 tables t1 , t2. want insert data t2 based on conditions of t1.
say t1 has data
sid linkname s1 link1 s1 link2 s2 link1 s2 link2 s2 link3 s3 link2
i want insert data new table t2 having above link1, link2 etc columns in such way if s1 has link 1 column link1 show yes , on. example s3, column of link1 , link3 show no, link2 column show yes
sid link1 link2 link3 s1 yes yes no s2 yes yes yes s3 no yes no
just run query:
select sid, max(case when linkname = 'link1' 'yes' else 'no' end) link1, max(case when linkname = 'link2' 'yes' else 'no' end) link2, max(case when linkname = 'link3' 'yes' else 'no' end) link3 t1 group sid;
you can use create table as
or insert
add information table.
note: uses fact 'yes'
> 'no'
.
Comments
Post a Comment