mysql全连接的代替方法

    技术2022-05-19  24

       在MySQL中没有全连接,不知道是它觉得没有必要实现还是怎么的,反正就没有。但今天遇见这样一个表,想到要使用全连接。就使用左右连接代替了。

    该表是这样的,存储了两类信息。在显示的时候需要将这两类信息用列的方式显示。有人说可以用case when实现阿,但是这两类信息具体内容是不知道的,只有一个分类标志。飞花少说,代码如下。只是个人笔记使用。若你也遇见同样的问题,希望能够对你有所帮助。set @x=NULL; set @y=NULL; set @m=NULL; set @n=NULL; select * from ( select uuid,outc,outg,outcolor,outinflag,inc,ing from ( select @x:=ifnull(@x,0)+1 as tid,uuid,outincontent as outc,outingross outg,outincolor outcolor,outinflag from outinrec where outinflag=1) a left join ( select @y:=ifnull(@y,0)+1 as tid,outincontent as inc,outingross as ing from outinrec where outinflag=0) b on a.tid=b.tid union select uuid,outc,outg,outcolor,outinflag,inc,ing from ( select @m:=ifnull(@m,0)+1 as tid,outincontent as outc,outingross outg,outincolor outcolor from outinrec where outinflag=1) a right join ( select @n:=ifnull(@n,0)+1 as tid,uuid,outincontent as inc,outingross as ing ,outinflag from outinrec where outinflag=0) b on a.tid=b.tid ) c where outinflag=if(@x>@y,1,0) 


    最新回复(0)