Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sql server到mysql的转换_Mysql_Sql_Sql Server - Fatal编程技术网

sql server到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

我试图在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,  '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;

您收到的错误消息是什么?