一个最大值的问题
有表如下,要从中把开始和结束日期在2007-01-26到2007-02-25之间同时开始日期最大的几条数据取出来。
开始日期 结束日期 A B C
2006-12-26 2007-01-25 A A 1000
2006-12-26 2007-01-25 A B 1000
2007-01-12 2007-01-25 B D 1000
2007-01-12 2007-01-25 C W 1000
2007-01-26 2007-02-25 D F 1000
2007-01-26 2007-02-25 A W 1000
2007-02-12 2007-02-25 A B 1000
2007-02-12 2007-02-25 B L 1000
2007-02-26 2007-03-25 E T 1000
2007-02-26 2007-03-25 F N 1000
------解决方案--------------------SELECT * FROM Table
WHERE 开始日期 IN
(
SELECT MAX(开始日期) FROM Table
WHERE 开始日期 BETWEEN '2007-01-26 ' AND '2007-02-25 '
)
AND 开始日期 BETWEEN '2007-01-26 ' AND '2007-02-25 '
AND 结束日期 BETWEEN '2007-01-26 ' AND '2007-02-25 '