我有2个表我想从Requirement表中选择过去15天内RService和RSubService ='No Requirement'的记录以及表EnquiryMaster表中对应的MobileIT和PhoneIT是否为空或未输入
EnquiryMaster
[EnquiryId]
,[Company]
,[HeadOfficeAddress]
,[ContactPersonIT]
,[EmailIT]
,[MobileIT]
,[PhoneIT]
,[date]
Requirement-
[RequirementID]
,[EnquiryID]
,[Company]
,[RService]
,[RSubService]
,[RDetails]
,[RDate]
答案 0 :(得分:2)
select *
from dbo.EnquiryMaster as em
left join dbo.Requirement as r
on em.EnquiryId = r.EnquiryID
where r.MobileIT is null
and r.PhoneIT is null
and em.RService ='No Requirement'
and em.RSubService ='No Requirement'
and em.date >= dateadd(day, -15, getdate())
答案 1 :(得分:1)
select * from EnquiryMaster em
inner join Requirement r on r.EnquiryId = em.EnquiryID
where r.MobileIT is null and r.PhoneIT is null and em.RSubService ='No Requirement'
答案 2 :(得分:1)
select * from EnquiryMaster e, Requirement r
where e.EnquiryId = r.EnquiryID
and RService = 'No Requirement'
and RSubService = 'No Requirement'