写出一条SQL语句,检索出日期最接近10/01的产品价格(不超过10/01)
Table name: pp
Fields:
ID integer
Date varchar(5)
Price integer
表中的数据有:
ID Date Price
1 10/02 1
2 10/06 2
2 10/03 4
3 10/01 5
3 09/30 4
检索出的结果应该为:
ID Date Price
1 10/02 1
2 10/03 4
3 10/01 5
答案:
select * from pp as X
where date>="10/01" and date<=ALL(select date from pp as Y where X.id=Y.id and Y.date>="10/01")
group by id