sql-server to mysql translation -
i'm trying recreate in mysql created in ms sql. i'm having heck of time getting syntax right. know equivalent mysql query following:
create table #tmp (id int, ran varchar(10), result int, ref_id int) insert #tmp values (1, 'object1', 4.0, 1) insert #tmp values (2, 'object2', 100, 1) insert #tmp values (3, 'object1', 6.0, 2) insert #tmp values (4, 'object3', 89.0, 2) select * #tmp select t.ref_id ,tk = max(case when t.ran ='object1' t.[result] end) ,crp= max(case when t.ran ='object2' t.[result] end) ,hpt= max(case when t.ran = 'object3' t.[result] end) #tmp t group t.ref_id
thank taking look!
this doesn't seem difficult:
create temporary table tmp ( id int, ran varchar(10), result int, ref_id int ); insert tmp(id, ran, result, ref_id) values (1, 'object1', 4.0, 1); insert tmp(id, ran, result, ref_id) values (2, 'object2', 100, 1); insert tmp(id, ran, result, ref_id) values (3, 'object1', 6.0, 2); insert tmp(id, ran, result, ref_id) values (4, 'object3', 89.0, 2); select * tmp; select t.ref_id, max(case when t.ran ='object1' t.result end) tk, max(case when t.ran ='object2' t.result end) crp, max(case when t.ran = 'object3' t.result end) hpt tmp t group t.ref_id;
here pretty close sql fiddle.
Comments
Post a Comment