我的记录:
SF_ID CardID Status Received_Date Meetup_Date
12 1 Yes 2015-01-12 2015-12-03
13 1 No 2015-12-01 NULL
14 1 No 2015-12-01 NULL
15 2 No 2015-12-02 NULL
16 2 No 2015-12-02 NULL
17 3 No 2015-12-01 NULL
18 4 No 2015-12-06 NULL
19 5 Yes 2015-11-30 2015-12-01
20 5 No 2015-11-30 NULL
22 5 No 2015-11-30 NULL
23 7 yes 2015-12-06 2015-12-07
要求#1:
所有cardID
,其中Received_Date
为最低Status
是No
和Top 01 SF_ID
。我没有成功地尝试过以下方式:
SELECT CardSFID,
CardID,
CardSFShortDate
FROM CC_Shortfall AS [data]
WHERE ( CardSFShortDate = (SELECT TOP 1 PERCENT CardSFShortDate
FROM CC_Shortfall
WHERE CardID = [data].CardID) )
AND CardSFYesNo = 'No'
要求#2:
所有cardID
其中MeetUp_Date
为最高且Status
是Yes
,No Status
CardID
我试图在没有成功的情况下以下列方式进行此操作:
SELECT CardSFID,
CardID,
CardSfShortRcvDate
FROM CC_Shortfall AS [data]
WHERE ( CardSfShortRcvDate = (SELECT Max(CardSfShortRcvDate)
FROM CC_Shortfall
WHERE CardID = [data].CardID) )
AND CardSFYesNo = 'Yes'