木子Maple先森

博客园 首页 联系 订阅 管理

sql连表查询找不到关联字段时? 怎么做?

我们可以 在查询表时虚拟一个字段,然后两个表都虚拟一个字段 ,比如new ,old对比。如图

 此图说明 应为new和old,但是new新表数据清了。。。

 

对应sql:

select * from (
select 'new' cdrsource,to_char(BEGIN_TIME,'YYYYMMDDHH24MISS') begin_time ,FILE_NAME,CDR_TYPE_ID,FILE_SN,USER_ID,CALL_TYPE,ORG_CALLING_AREA_CODE,SERVICE_NUMBER,AREA_CODE,ORG_CALLING_NUMBER,ORG_CALLED_AREA_CODE,OPPOSE_NUMBER,OPPOSE_AREA_CODE,ORG_CALLED_NUMBER,CONNECT_NUMBER,DURATION,FEE_CODE_A,FEE_CODE_B,FEE_A,FEE_B,IMSI,IMEI,ROAM_AREA,PLMN,ROAM_TYPE,STANDARD_FEE,LONG_TYPE,FORWARD_CDR_TYPE,IS_SPECIAL,TRACK,INSERT_TIME,CHARGE_FLAG,ORG_LONG_TYPE,ORG_ROAM_TYPE,PARTITION_ID,KEYS,RATING_TIME,OFFER_ID,RESOURCE_FLAG,CARRIER_TYPE,CARRIER_NUMBER
from CDR_voice_07
union all
select 'old' cdrsource,to_char(BEGIN_TIME,'YYYYMMDDHH24MISS') begin_time, FILE_NAME,CDR_TYPE_ID,FILE_SN,USER_ID,CALL_TYPE,ORG_CALLING_AREA_CODE,SERVICE_NUMBER,AREA_CODE,ORG_CALLING_NUMBER,ORG_CALLED_AREA_CODE,OPPOSE_NUMBER,OPPOSE_AREA_CODE,ORG_CALLED_NUMBER,CONNECT_NUMBER,DURATION,FEE_CODE_A,FEE_CODE_B,FEE_A,FEE_B,IMSI,IMEI,ROAM_AREA,PLMN,ROAM_TYPE,STANDARD_FEE,LONG_TYPE,FORWARD_CDR_TYPE,IS_SPECIAL,TRACK,INSERT_TIME,CHARGE_FLAG,ORG_LONG_TYPE,ORG_ROAM_TYPE,PARTITION_ID,KEYS,RATING_TIME,OFFER_ID,RESOURCE_FLAG,CARRIER_TYPE,CARRIER_NUMBER
from CDR_voice_07_old ) where user_id = '41104000606519'
-- and begin_time not in ('20170731232033','20170630233018','20170630233019')
order by begin_time,cdrsource;

posted on 2017-09-20 15:00  木子Maple先森  阅读(907)  评论(0编辑  收藏  举报