我有两个表,一个是example 1: input [user_id = 1, user_id = 2] output => 55,66
example 2: input [user_id = 1, user_id = 3] output => 44,55,66
example 3: input [user_id = 1, user_id = 4] output => null
,另一个是CurrentReport
表,另一个是表中显示的当前报告表。我复制currentReport表的以下列的值
Challan
但是现在我想将具有最小日期的challan表的stepno复制到两个表中的currentreport表的work1中。是一样的在challan表中,challan表中有多个enteries,具有相同的引用号,其中我想获得具有最小日期的stepno。
[Title],
[ISBN],
[Author1],
[FinalStatus],
[MssType]
表中的列是
challan
[ChallanNo]
,[ReferenceNo]
,[PersonID]
,[PersonCategory]
,[ChallanDate]
,[PreparedBy]
,[CreatedOn]
,[Publisher]
,[TemplateName]
,[TemplateSubject]
,[TemplateBody]
,[EmailAttachment]
,[PreviousProjectedDate]
,[PreviousReminderDate]
,[PreviousActionDate]
,[NextProjectedDate]
,[NextReminderDate]
,[NextActionDate]
,[ReminderText]
,[ReceivedDate]
,[StepNo]
,[ChallanStatus]
,[IsActive]
,[IsReceived]
表中的列是:
CurrentReport
所以请告诉我如何更新 [ReferenceNo]
,[Title]
,[ISBN]
,[Author1]
,[FinalStatus]
,[MssType]
,[Work1]
,[GivenTo1]
,[ChallanDate1]
,[ReceivedDate1]
,[Work2]
,[GivenTo2]
,[ChallanDate2]
,[ReceivedDate2]
,[Work3]
,[GivenTo3]
,[ChallanDate3]
,[ReceivedDate3]
,[Work4]
,[GivenTo4]
,[ChallanDate4]
,[ReceivedDate4]
表,因为它有200个条目,currentreport
表有700个进入。
答案 0 :(得分:1)
/ *检查这是否有效* / 第1步 - 写入select来过滤掉minDate -
http://www.therapy-directory.org.uk/therapists/lesley-lister?uqs=626693
http://www.therapy-directory.org.uk/therapists/fiona-jeffrey?uqs=626693
http://www.therapy-directory.org.uk/therapists/ann-grant?uqs=626693
.....
.....
http://www.therapy-directory.org.uk/therapists/jan-garbutt?uqs=626693
/ *如果以上工作正常* / 第2步 - 根据上述结果进行更新
SELECT c.ChallanNo, c.REFERENCENO , c.STEPNO FROM CHALLAN c
INNER JOIN CURRENTREPORT cr
on c.REFERENCENO = cr.REFERENCENO
WHERE RECEIVEDDATE IN (SELECT MIN(RECEIVEDDATE)
FROM CHALLAN cn
GROUP BY (STEPNO))