我在SQLite3中有此表price_date
。
id info_id price date
"661" "1" "15.99" "2018-10-15"
"1334" "1" "18.52" "2018-10-01"
"439" "2" "24.48" "2018-10-15"
"1113" "2" "25.97" "2018-10-01"
"2" "6" "0.64" "2018-10-15"
"678" "6" "0.66" "2018-10-01"
我想检索具有最新日期的记录,以使输出看起来像这样;
id info_id price date
"661" "1" "15.99" "2018-10-15"
"439" "2" "24.48" "2018-10-15"
"2" "6" "0.64" "2018-10-15"
是否有任何开始编写sql代码的提示?
答案 0 :(得分:4)
使用相关子查询
select * from price_date t
where t.date =
( select max(date) from price_date t1
where t1.info_id=t.info_id
)
答案 1 :(得分:2)
使用相关子查询
select * from tablename t1 where date in
(select max(date) from tablename t2 where t1.info_id=t2.info_id)