sql的select查询添加一个虚拟字段进去

sql select语句查询的时候增加一个字段到结果里:

select * from ( 
select id,title,uId,fabuTime,'招商' AS name  from zhaoshangInfo 
union all 
select id,title,userId AS uId,createTime AS fabuTime,'求职' AS name from resume 
union all 
select id,title,uId,fabutime AS fabuTime,'招聘' AS name from zhaopin
union all 
select id,title,uId,fabuTime,'加盟' AS name from jiamengInfo
)d WHERE uId IN(1,349) ORDER BY fabuTime DESC

像上面需要取多张表的数据存合并成一张表的时候,有时候为了区分哪些数据是出自于具体的哪张表,可以加一个表的标识字段进去,这样就方便明了多了。例如上面的“‘招商‘ AS name ”,“‘求职‘ AS name ”,“‘招聘‘ AS name ”,“‘加盟’‘ AS name ”。

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页