0

我只想从 Division_Program 列中获取最新记录。“JMSDay”列数据中的数据填充了一周中的第 7 天。我用一个数组来缩写日子(即周一到周日)。“JMS_UpdateTime”列数据使用以下格式 8/4/2013 1:02:12 PM

SELECT top 1 * 
FROM CensusFacility_Records 
WHERE JMSDay = '" & smDateArray (Weekday(date)) & "' 
AND Division_Program ='" & divrec &"' 
order by JMS_UpdateDateTime desc
4

1 回答 1

1
WITH Census AS
(
    SELECT
     *
    ,ROW_NUMBER() OVER(ORDER BY JMS_UpdateDateTime DESC) AS RowID
    FROM CensusFacility_Records
    WHERE JMSDay = '" & smDateArray (Weekday(date)) & "' 
    AND Division_Program ='" & divrec &"' 
)
SELECT * FROM Census
WHERE RowID=1;
于 2013-08-21T14:24:14.937 回答