在数据库查询数据的时候,比如查询出type需要根据不用的值,换一个别名,在程序中循环处理有点麻烦,现在有一个方法就是用临时表跟查询表连接查询即可。所以现在需要新建一个临时表,然后用左联接联合查询。
1、新建临时表
select '100' as val,'sc' as lx
UNION select '200' as val,'zy' as lx
UNION select '300' as val,'bg' as lx
UNION select '600' as val,'yy' as lx
2、连接查询
select ty.*,ta.* from table ta
left join (select '100' as val,'sc' as lx
UNION select '200' as val,'zy' as lx
UNION select '300' as val,'bg' as lx
UNION select '600' as val,'yy' as lx ) ty on ty.lx=ta.lx