sql連表查詢找不到關聯字段時?

sql連表查詢找不到關聯字段時? 怎麼作?sql

咱們能夠 在查詢表時虛擬一個字段,而後兩個表都虛擬一個字段 ,好比new ,old對比。如圖blog

 此圖說明 應爲new和old,可是new新表數據清了。。。io

 

對應sql:select

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;nio

相關文章
相關標籤/搜索