sql server到mysql的转换
我试图在mysql中重新创建在MS SQL中创建的东西。我花了很长时间把语法弄对了。是否有人知道以下内容的等效mysql查询是什么:sql server到mysql的转换,mysql,sql,sql-server,Mysql,Sql,Sql Server,我试图在mysql中重新创建在MS SQL中创建的东西。我花了很长时间把语法弄对了。是否有人知道以下内容的等效mysql查询是什么: 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, 'O
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 * from #tmp
Select t.ref_id
,TK = max(case when t.Ran ='Object1' then t.[Result] end)
,CRP= max(case when t.Ran ='Object2' then t.[Result] end)
,HPT= max(case when t.Ran = 'Object3' then t.[Result] end)
From #tmp t
group by t.ref_id
谢谢你看 这似乎并不难:
create temporary table tmp (
id int,
Ran varchar(10),
Result int,
ref_id int
);
insert into tmp(id, Ran, Result, ref_id) values (1, 'Object1', 4.0, 1);
insert into tmp(id, Ran, Result, ref_id) values (2, 'Object2', 100, 1);
insert into tmp(id, Ran, Result, ref_id) values (3, 'Object1', 6.0, 2);
insert into tmp(id, Ran, Result, ref_id) values (4, 'Object3', 89.0, 2);
select * from tmp;
Select t.ref_id,
max(case when t.Ran ='Object1' then t.Result end) as TK,
max(case when t.Ran ='Object2' then t.Result end) as CRP,
max(case when t.Ran = 'Object3' then t.Result end) as HPT
From tmp t
group by t.ref_id;
是一个非常接近SQL的查询。上述SQL查询的MySQL等价查询:
create table #tmp
(id int, Ran varchar(10), Result int, ref_id int);
insert into #tmp values (1, 'Object1', 4.0, 1);
insert into #tmp values (2, 'Object2', 100, 1);
insert into #tmp values (3, 'Object1', 6.0, 2);
insert into #tmp values (4, 'Object3', 89.0, 2);
select * from #tmp;
Select t.ref_id
,TK = max(case when t.Ran ='Object1' then t.Result end)
,CRP= max(case when t.Ran ='Object2' then t.Result end)
,HPT= max(case when t.Ran ='Object3' then t.Result end)
from #tmp t
group by t.ref_id;
您收到的错误消息是什么?