如何使用左连接从多个表中获取值?
How to use get value from multiple tables using left join?
我有这 3 个 Table。现在,我需要使用左连接在设备 Table 中显示来自时区 table 的时区名称。
我怎样才能做到这一点?请帮忙
Table 姓名:[pbi].[GEOTAB_INFO_GROUPS]
GROUP_ID| GROUP_NAME |LOCATION_ID |IMPORTDATE
b27FA | 55310 | 55310 | 20220328
b282B | 35824 | 35824 | 20220328
b2797 | 55876 | 55876 | 20220328
Table 姓名:[adl].[GEOTAB_VEHICLE_INFO_DEVICES]
Id Name SerialNumber ActiveFrom ActiveTo DeviceType DevicePlans VehicleIdentificationNumber LicensePlate LicenseState WorkTime ProductId HardwareId TimeZoneId Group_Id Comment ImportDate ImportTime
b957 09-101-57218 3G 000-000-0000 2017-07-05 23:59:52 2022-01-20 20:24:28 OldGeotab ProPlus 15GGD271991176896 7063-OP PR Standard Hours 0 NULL America/New_York b2A06 NULL 20220330 2022-03-30 7:00:58
Table 姓名:[pbi].[Location_Time_Zone]
LocationNumber TimeZone ImportDate ImportTime
301194 Central 20211007 07-10-2021 18:44:57
我正在这样尝试,但没有得到正确的结果
select distinct d.Id, g.LOCATION_ID, d.Name, d.SerialNumber, d.ActiveFrom, d.ActiveTo, d.DeviceType, d.DevicePlans, d.VehicleIdentificationNumber, d.LicensePlate, d.LicenseState, d.WorkTime, d.ProductId, d.HardwareId, d.TimeZoneId, tz.TimeZone, d.Groups, d.Comment, d.ImportDate
from [adl].[GEOTAB_VEHICLE_INFO_DEVICES] d
left join [pbi].[GEOTAB_INFO_GROUPS] g
on d.Groups = g.GROUP_ID
left join [pbi].[Location_Time_Zone] tz
on tz.LocationNumber = g.LOCATION_ID
Select d.*, t.TimeZone
From [adl].[GEOTAB_VEHICLE_INFO_DEVICES] d
Left Join [pbi].[GEOTAB_INFO_GROUPS] g ON g.Group_Id= d.Group_Id
Left Join [pbi].[Location_Time_Zone] t ON g.Location_Id = t.LocationNumber
在 SAP ABAP 中,我们使用此代码来使用左联接:
tables : GEOTAB_VEHICLE_INFO_DEVICES,
GEOTAB_VEHICLE_INFO_DEVICES.
select a~GROUP_ID a~GROUP_NAME a~LOCATION_ID a~IMPORTDATE a~b27FA a~55310 a~55310 a~20220328 a~b282B a ~35824 a~35824 a~20220328 a~b2797 a~55876 a~55876 a~20220328 a~b2798 a~55888 a~55888 a~20220328 a~b2812 a~55497 a~55497 a~20220328 a~b25470 a~5 a~55475 a~20220328 a~b27B3 a~57233 a~57233 a~20220328 a~b27EC a~55616 a~55616 a~20220328 来自 table GEOTAB_VEHICLE_INFO_DEVICES 作为使用左外连接 b~Id b~名称 b~序列号 b~ActiveFrom b~ActiveTo b~DeviceType b~DevicePlans b~VehicleIdentificationNumber b~LicensePlate b~LicenseState b~WorkTime b~ProductId b~HardwareId b~TimeZoneId b~Group_Id b~Comment b ~ImportDate b~ImportTime from table GEOTAB_VEHICLE_INFO_DEVICES as B on a~GroupId eq b~GroupID using left outer join c~b957 c~09-101-57218 c~3G c~000-000-0000 c~2017-07-05 c~23:59:52 c~2022-01-20 c~20:24:28 c~OldGeotab c~ProPlus c~15GGD271991176896 c~7063-OP c~PR c~标准 c~小时 c~0 c~NULL c~America/New_York c~b2A06 c~NULL c~20220330 c~2022-03-30 c~7:00:58
来自 table Location_Time_Zone as c on b~TimeZoneId eq c~TimeZone.
我有这 3 个 Table。现在,我需要使用左连接在设备 Table 中显示来自时区 table 的时区名称。 我怎样才能做到这一点?请帮忙
Table 姓名:[pbi].[GEOTAB_INFO_GROUPS]
GROUP_ID| GROUP_NAME |LOCATION_ID |IMPORTDATE
b27FA | 55310 | 55310 | 20220328
b282B | 35824 | 35824 | 20220328
b2797 | 55876 | 55876 | 20220328
Table 姓名:[adl].[GEOTAB_VEHICLE_INFO_DEVICES]
Id Name SerialNumber ActiveFrom ActiveTo DeviceType DevicePlans VehicleIdentificationNumber LicensePlate LicenseState WorkTime ProductId HardwareId TimeZoneId Group_Id Comment ImportDate ImportTime
b957 09-101-57218 3G 000-000-0000 2017-07-05 23:59:52 2022-01-20 20:24:28 OldGeotab ProPlus 15GGD271991176896 7063-OP PR Standard Hours 0 NULL America/New_York b2A06 NULL 20220330 2022-03-30 7:00:58
Table 姓名:[pbi].[Location_Time_Zone]
LocationNumber TimeZone ImportDate ImportTime
301194 Central 20211007 07-10-2021 18:44:57
我正在这样尝试,但没有得到正确的结果
select distinct d.Id, g.LOCATION_ID, d.Name, d.SerialNumber, d.ActiveFrom, d.ActiveTo, d.DeviceType, d.DevicePlans, d.VehicleIdentificationNumber, d.LicensePlate, d.LicenseState, d.WorkTime, d.ProductId, d.HardwareId, d.TimeZoneId, tz.TimeZone, d.Groups, d.Comment, d.ImportDate
from [adl].[GEOTAB_VEHICLE_INFO_DEVICES] d
left join [pbi].[GEOTAB_INFO_GROUPS] g
on d.Groups = g.GROUP_ID
left join [pbi].[Location_Time_Zone] tz
on tz.LocationNumber = g.LOCATION_ID
Select d.*, t.TimeZone
From [adl].[GEOTAB_VEHICLE_INFO_DEVICES] d
Left Join [pbi].[GEOTAB_INFO_GROUPS] g ON g.Group_Id= d.Group_Id
Left Join [pbi].[Location_Time_Zone] t ON g.Location_Id = t.LocationNumber
在 SAP ABAP 中,我们使用此代码来使用左联接:
tables : GEOTAB_VEHICLE_INFO_DEVICES, GEOTAB_VEHICLE_INFO_DEVICES.
select a~GROUP_ID a~GROUP_NAME a~LOCATION_ID a~IMPORTDATE a~b27FA a~55310 a~55310 a~20220328 a~b282B a ~35824 a~35824 a~20220328 a~b2797 a~55876 a~55876 a~20220328 a~b2798 a~55888 a~55888 a~20220328 a~b2812 a~55497 a~55497 a~20220328 a~b25470 a~5 a~55475 a~20220328 a~b27B3 a~57233 a~57233 a~20220328 a~b27EC a~55616 a~55616 a~20220328 来自 table GEOTAB_VEHICLE_INFO_DEVICES 作为使用左外连接 b~Id b~名称 b~序列号 b~ActiveFrom b~ActiveTo b~DeviceType b~DevicePlans b~VehicleIdentificationNumber b~LicensePlate b~LicenseState b~WorkTime b~ProductId b~HardwareId b~TimeZoneId b~Group_Id b~Comment b ~ImportDate b~ImportTime from table GEOTAB_VEHICLE_INFO_DEVICES as B on a~GroupId eq b~GroupID using left outer join c~b957 c~09-101-57218 c~3G c~000-000-0000 c~2017-07-05 c~23:59:52 c~2022-01-20 c~20:24:28 c~OldGeotab c~ProPlus c~15GGD271991176896 c~7063-OP c~PR c~标准 c~小时 c~0 c~NULL c~America/New_York c~b2A06 c~NULL c~20220330 c~2022-03-30 c~7:00:58 来自 table Location_Time_Zone as c on b~TimeZoneId eq c~TimeZone.