![](/img/trans.png)
[英]Sqlite3 to retrieve earliest and latest records for a particular ID and DEPT
[英]Retrieve records of latest dates in sqlite
我在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代码的任何提示?
使用相关子查询
select * from price_date t
where t.date =
( select max(date) from price_date t1
where t1.info_id=t.info_id
)
使用相关子查询
select * from tablename t1 where date in
(select max(date) from tablename t2 where t1.info_id=t2.info_id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.