dongtong2021 2010-12-23 02:17 采纳率: 0%
浏览 14

我在查询中需要Sql帮助

what query would I use to do the following

Name1 Version1 xAmount

Name1 Version2 xAmount

Name2 Version1 xAmount

Name2 Version2 xAmount

Name2 Version3 xAmount

Name3 Version1 xAmount

according to this The latest version for Name1 is Version2, and the latest version for Name2 is Version3, and Name3 is Version1.

How would i create a query to grab each name with the latest version, assuming the latest version is an integer or something like 1.2a and 1.2b

  • 写回答

2条回答 默认 最新

  • duanfang7757 2010-12-23 02:24
    关注

    use the following

    select Name,Version, Amount
    From T1,(select Name,max(Version) as Version From T1 Group By Name) as T2
    Where T1.Name=T2.Name and T1.Version=T2.Version
    

    and if you have an ID for the table

    select Name,Version, Amount
    From T1,(select max(ID) as ID From T1 Group By Name) as T2
    Where T1.ID=T2.ID
    

    Or

    select Name,Version, Amount
    From T1
    Where T1.ID IN (select max(ID) as ID From T1 Group By Name)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?