Please help. I am not sure if Redshift has an issue or if it is just me.
Table A has the below data:
Company_Name | Report_Type | Report_Number |
---|---|---|
Apple | Sales | 123 |
Apple | Employees | 804 |
Table B has the below data:
Report_Number | Report_Type |
---|---|
123 | Sales |
804 | Employees |
654 | Inventory |
Revenue |
I need the below output, ie to add missing report_types to Table A:
Company_Name | Report_Type | Report_Number |
---|---|---|
Apple | Sales | 123 |
Apple | Employees | 804 |
Apple | Inventory | 654 |
Apple | Revenue |
select t2.Company_Name , t1.Report_Type
from (select distinct Report_Type from TableB) t1
cross join (select distinct Company_Name from tableA) t2
where not exists (select 1 from tableA t3
where t3.Company_Name = t2.Company_Name
and t3.Report_Type = t1.Report_Type
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.