查询从两个表中获取数据并将它们一起返回
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查询从两个表中获取数据并将它们一起返回相关的知识,希望对你有一定的参考价值。
关于使用sql-server,我有一个简单的问题。我有两张桌子,一张用于保险公司,另一张用于约会。我的目标是创建一个查询,我抓住所有使用两个特定保险公司的约会。例如,我希望所有使用州农场和USAA作为其保险公司的任务。
SELECT TOP (1000) [Id]
,[Name]
,[AddressOne]
,[AddressTwo]
,[City]
,[State]
,[Zip]
,[PrimaryPhone]
,[SecondaryPhone]
,[Fax]
,[InsurerStatusId]
,[InsuranceGroupId]
,[ModifiedDate]
,[ModifiedBy]
,[ReportInsuranceName]
,[ReportInsuranceId]
FROM [AssignmentManagement].[dbo].[Insurers]
SELECT TOP (1000) [Id]
,[AppointmentTypeId]
,[AssignmentId]
,[StaffId]
,[CalendarId]
,[AppointmentDate]
,[ScheduledDate]
,[RequestedAppointmentDate]
,[Notes]
,[Hour]
,[Minute]
,[DayOfTheWeek]
,[CenterId]
,[AppointmentStatusId]
,[RentalCar]
,[ScheduledBy]
FROM [AssignmentManagement].[dbo].[Appointments]
SELECT TOP (1000) [Id]
,[InsurerId]
,[RepairCategoryId]
,[AssignmentStatusId]
,[OriginalCenterId]
,[OriginalStaffId]
,[LossCategoryId]
,[ClaimNumber]
,[PolicyNumber]
,[LossDate]
,[TotalLossIndicator]
,[Source]
,[PrimaryCustomerType]
,[InsuredCustomerId]
,[OwnerCustomerId]
,[ClaimCustomerId]
,[CustomerServiceRepresentativeId]
,[TransactionId]
,[Towing]
,[RentalCar]
,[IsDriveIn]
,[Deductible]
,[DeductibleStatus]
,[PhotosOnly]
,[LeftMessageSequence]
,[VehicleYear]
,[VehicleMake]
,[VehicleMakeDescription]
,[VehicleModel]
,[VehicleColor]
,[VIN]
,[Odometer]
,[LicenseNumber]
,[LicenseState]
,[VehicleLocationName]
,[VehicleAddressOne]
,[VehicleAddressTwo]
,[VehicleCity]
,[VehicleState]
,[VehicleZip]
,[VehiclePhone1]
,[VehiclePhone1Ext]
,[VehiclePhone2]
,[VehiclePhone2Ext]
,[VehicleContactFirstName]
,[VehicleContactLastName]
,[VehicleCondition]
,[VehicleNotes]
,[Impact1]
,[Impact2]
,[ClaimOfficeName]
,[AgentName]
,[AgentFirstName]
,[AgentLastName]
,[AgentAddressOne]
,[AgentAddressTwo]
,[AgentCity]
,[AgentState]
,[AgentZip]
,[AgentLicenseNumber]
,[AgentPhone]
,[AgentPhoneExt]
,[AgentFax]
,[AgentEmail]
,[PriorDamage]
,[Notes]
,[DamageNotes]
,[SpecialInstructions]
,[DispatchNotes]
,[LossNotes]
,[OtherNotes]
,[AssignmentDate]
,[ReportDate]
,[NextCallDate]
,[CreateDate]
,[CreatedBy]
,[IsEstimateMatch]
,[IsROMatch]
,[IsDriveable]
,[ModifiedDate]
,[UpdatedBy]
,[AccessedBy]
,[LegacyAsgnNavId]
,[LegacyAsgnNo]
,[AssignmentStatusReasonId]
,[RentalAgencyId]
,[Estimate_Id]
,[NextCallDateUpdatedBy]
,[RentalReservationNumber]
,[IsHail]
,[InitialOriginatingCenterId]
,[UnscheduledDropId]
,[UnscheduledExplanation]
,[RepairLevelId]
,[AdjusterFirstName]
,[AdjusterLastName]
,[AdjusterPhoneExt]
,[AdjusterPhoneNumber]
,[VehicleTrim]
,[VehicleOptions]
,[AdditionalInformation]
,[DeliveryLocation]
,[DeliveryCenterId]
,[RequestedAppointmentDate]
FROM [AssignmentManagement].[dbo].[Assignments]
以上是关于查询从两个表中获取数据并将它们一起返回的主要内容,如果未能解决你的问题,请参考以下文章
python 如何获取从数据库查询返回的元组并将它们转换为命名元组。
如何从两个不同的、不相关的表中获取最新的行,并将它们合并到一个结果集中?