查询最新单价

summerwit 2003-01-05 01:11:10
比如有这样一个表:
item Unit Date
1222 0.232 05-01-2002
1222 0.113 06-12-2002
1003 1.02 02-02-2002


要求用一条语句实现以item为group查询出其最新单价
...全文
44 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zlyanyan 2003-01-07
  • 打赏
  • 举报
回复
楼上的朋友的观点是对的
cyberflying 2003-01-06
  • 打赏
  • 举报
回复
楼上:
不会错的。
有where t2.itme = t1.item,就不会有另一个item的问题!
beckhambobo 2003-01-06
  • 打赏
  • 举报
回复
to cyberflying(雁南飞) 有问题,若另一个itme有相同日期也会被查出来

select a.* from table a where (a.item,a.date) in (select item,max(date) mdate from table b group by item)
cyberflying 2003-01-06
  • 打赏
  • 举报
回复
select * from yourtable t1
where t1.date = (select max(date)
from yourtable t2
where t2.itme = t1.item)
bzszp 2003-01-06
  • 打赏
  • 举报
回复
select t1.item,unit from (select item,max(date) mdate from tbname group by item) t1,tbname where t1.item = tbname.item and t1.mdate = tbname.date;

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧