0

我有这个 SQL 语句:

SELECT *
FROM history
WHERE (fk_person = 2119) AND (action = 2) AND (date =
                                                      (SELECT MAX(day) AS maxDay
                                                       FROM history AS hist
                                                       WHERE (fk_person = 2119)))

据我所知 SQL Server CE 不支持子查询。

我该如何更换它?

感谢您的回答!

4

2 回答 2

2

尝试

SELECT h1.*
FROM history h1
inner join FROM history h2 on h1.fk_person = h2.fk_person
WHERE h1.fk_person = 2119
AND h1.action = 2
AND h1.day = MAX(h2.day)
于 2012-06-08T07:38:34.370 回答
0

我不确定有多少记录相同MAX(day),但如果您只需要一个,以下可能对您有用:

SELECT TOP (1) *
FROM history
WHERE (fk_person = 2119)
AND (action = 2) 
ORDER BY day DESC
于 2012-06-08T07:43:33.683 回答