如何比较两个包含数百万个条目但列不同的表

时间:2019-04-11 16:08:31

标签: sql oracle

我有两个桌子。一列包含三列,第二列包含更多列,我希望两个表之间的对应值成为包含最多列的表的对应值。

请注意,我尝试使用此代码,但值均为null 谢谢。

SELECT 
plate_lable.numbers, 
plate_lable.governorate, 
plate_lable.usage,
TO_CHAR(NULL) "chassis",
TO_CHAR(NULL) "brand",
TO_CHAR(NULL) "vehicle_production_year",
TO_CHAR(NULL) "DATES",
TO_CHAR(NULL) "use_case"
FROM  
plate_lable 

INTERSECT

SELECT 
t_registered_unit.numbers AS numbers,
t_registered_unit.governorate AS governorate,
t_registered_unit.usage AS usage,
t_registered_unit.chassis as chassis,
t_registered_unit.brand as brand,
t_registered_unit.vehicle_production_year as vehicle_production_year,
TO_CHAR(CAST(t_registered_unit.CREATED AS DATE), 'YYYY\MM\dd') AS DATES,
t_registered_unit.use_case as use_case
FROM
t_registered_unit

1 个答案:

答案 0 :(得分:0)

SELECT 
  t1.numbers, 
  t1.governorate, 
  t1.usage,
  t2.chassis as chassis,
  t2.brand as brand,
  t2.vehicle_production_year as vehicle_production_year,
  TO_CHAR(CAST(t2.CREATED AS DATE), 'YYYY\MM\dd') AS DATES,
  t2.use_case as use_case

FROM  
  plate_lable                  t1
  inner join t_registered_unit t2
ON
  t1.numbers      = t2.numbers     and
  t1.governorate  = t2.governorate and
  t1.usage        = t2.usage ;