如何在SQL中获取对象的所有版本和最新迭代 [英] how to get all version and latest iteration of object in the SQL

查看:130
本文介绍了如何在SQL中获取对象的所有版本和最新迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SQL还是很陌生...

I'm very new to SQL...

我在名为versioniteration的表中有如下数据.我想在SQL(oracle)中建立查询以获取第二张表中所示的信息.请指导我该怎么做?

I have data like below in table called versioniteration. I want build a query in SQL (oracle) to get the out as in the second table. Please guide me how to do this?

在给定版本中,每次更改使迭代次数增加时,零件都会多次更改.

Here the part get altered many times in given version, each time the changes made the iteration increases.

该零件也可以更改为新版本,然后将分配迭代(编号).

The part can also change to new version then the Iteration will be assigned (number).

| Name          | Version       | Iteration  |
|===============|===============|============|
| Part 1        |      A        |    1       |
|:------------------------------------------:|
| Part 1        |      A        |    2       |
|:------------------------------------------:|
| Part 1        |      A        |    3       |
|:------------------------------------------:|
| Part 1        |      B        |    0       |
|:------------------------------------------:|
| Part 1        |      B        |    1       |
|:------------------------------------------:|
| Part 1        |      B        |    2       |
|:------------------------------------------:|
| Part 2        |      D        |    1       |
|:------------------------------------------:|
| Part 2        |      D        |    2       |
|:------------------------------------------:|
| Part 2        |      D        |    3       |
|:------------------------------------------:|
| Part 2        |      C        |    0       |
|:------------------------------------------:|
| Part 2        |      C        |    1       |
|:------------------------------------------:|
| Part 2        |      C        |    2       |
|:------------------------------------------:|

出局应该是:

| Name          | Version       | Iteration  |
|===============|===============|============|
| Part 1        |      A        |    3       |
|:------------------------------------------:|
| Part 1        |      B        |    2       |
|:------------------------------------------:|
| Part 2        |      C        |    2       |
|:------------------------------------------:|
| Part 2        |      D        |    3       |
|:------------------------------------------:|

推荐答案

Gordon Linoff所说的是基本的group by查询.您应该了解工作分组方式,并添加其他功能进行查询.例如,您的任务是group by + MAX.另请参阅此问题.

How said Gordon Linoff is basic group by query. You should understand how work group by and add other features to query. For example, your task is group by + MAX. Also look at this question.

您的查询:

SELECT name
     , version
     , MAX(iteration)
FROM table1
GROUP BY name, version

这篇关于如何在SQL中获取对象的所有版本和最新迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆