how to get all version and latest iteration of object in the SQL

久未见 提交于 2019-12-13 08:55:54

问题


I'm very new to SQL...

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       |
|:------------------------------------------:|

The out should be:

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

回答1:


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.

Your query:

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


来源:https://stackoverflow.com/questions/35353222/how-to-get-all-version-and-latest-iteration-of-object-in-the-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!