Mysql查询在一行中获得多个结果* EDITED *

时间:2017-06-29 11:44:33

标签: mysql

确定如何在这里完成标题......

但是,下面是我试图开始工作的MySQL查询(它已被破坏)

我想要实现的目标如下:

REP = 0 im AS deviceim

REP = 1 im AS replaceim

SELECT tb1.*, tb2.id AS iii, tb2.im as deviceim, (SELECT tb2.im FROM tb2 WHERE tb2.REP LIKE '1' AND tb1.filter IN ('SEPID1','SEPID2'...) ) AS replacementim 
FROM tb1 LEFT OUTER JOIN tb2 ON tb1.id = tb2.orderid 
AND tb2.REP LIKE '0' WHERE filter IN ('SEPID1','SEPID2'...) 
ORDER BY filter

根据要求提供更多信息进行编辑

数据

Table 1

id  

1

Table 2

id//////orderid//im/////REP

34567//////1///654311////0

63219//////1///827364////1

通缉输出:

id//deviceim/replacementim

1////654311/////827364
PS:我对格式化很抱歉!!

0 个答案:

没有答案