def hello():
def hi():
h = input("Hey")
if h == "Hey":
print("hi")
exit()
exit()
当SQL添加“备用批准人”(用于采购订单)时,它将为实际批准人创建一条附加记录。因此,试图找到一种方法来仅显示1条记录的批准人也有替代者。即“ jlhayes”有2条记录。一个带备用,另一个不带。对于这些记录,我只想查看具有备用记录的记录。谢谢您的帮助。我已经花了几个小时了,没想到。
答案 0 :(得分:0)
您可以将AltApprover
的case语句包装在max(AltApprover)
中,并按DAC.LocationCode, DAC.Description, ReqApp.Rank, App.Approver
分组,并对FromDate
和ToDate
进行类似的操作:
select DAC.LocationCode, DAC.Description, ReqApp.Rank, App.Approver as UserName,
max(CASE WHEN app.Approver = app.AlternateApprover THEN ''
ELSE AltApp.AlternateApprover END) As AltApprover,
max(ISNULL(CONVERT(Varchar,AltApp.FromDate,101),'')) AS FromDate,
max(ISNULL(CONVERT(Varchar,AltApp.ToDate,101),'')) AS ToDate
from tblAPAlternateApprovers App
INNER JOIN tblAPAlternateApprovers AltApp
ON App.ID = AltApp.ID
INNER JOIN tblAPReqLocations DAC
ON App.tblAPReqLocationsID = DAC.ID
INNER JOIN tblAPReqApprover ReqApp
ON App.Approver = ReqApp.Approver AND
App.tblAPReqLocationsID = ReqApp.LocationID
GROUP BY DAC.LocationCode, DAC.Description, ReqApp.Rank, App.Approver
ORDER BY DAC.LocationCode ASC, ReqApp.Rank asc