我有一条 SQL 语句。
SELECT ID, LOCATION, CODE,MAX(DATE) FROM TABLE1 WHERE
DATE <= CONVERT(DATETIME,'11-11-2012') AND
EXISTS(SELECT * FROM #TEMP_CODE WHERE TABLE1.CODE =#TEMP_CODE.CODE)
AND ID IN (14,279)
GROUP BY ID, LOCATION, CODE,(DATE)
我需要与 2012 年 11 月 11 日最近的日期的行,但该表返回所有值。我究竟做错了什么。谢谢
ID LOCATION CODE DATE
-------------------------------------------------------------------
14 CAR STREET,UDUPI 234 2012-08-08 00:00:00.000
14 CAR STREET,UDUPI 234 2012-08-10 00:00:00.000
14 CAR STREET,UDUPI 234 2012-08-14 00:00:00.000
279 MADHUGIRI 234 2012-08-08 00:00:00.000
279 MADHUGIRI 234 2012-08-11 00:00:00.000
我需要选择最大日期的行。所需的结果是
ID LOCATION CODE DATE
-------------------------------------------------------------------
14 CAR STREET,UDUPI 234 2012-08-10 00:00:00.000
279 MADHUGIRI 234 2012-08-11 00:00:00.000