1
...のMySQL - 次のデータを使用して、各データグループの見返り最後のレコード
+--------------+--------+---------------+-----------------+----------------+
| EQUIPMENT_ID | CML_ID | INSPECTION_NO | INSPECTION_DATE | WALL_THICKNESS |
+--------------+--------+---------------+-----------------+----------------+
| B1000-V001 | 1 | 1 | 1/01/2016 | 10 |
| B1000-V001 | 1 | 2 | 2/01/2016 | 9 |
| B1000-V001 | 1 | 3 | 3/01/2016 | 3 |
| B1000-V001 | 1 | 4 | 4/01/2016 | 7 |
| B1000-V001 | 1 | 5 | 5/01/2016 | 5 |
| B1000-V001 | 1 | 6 | 6/01/2016 | 4 |
| B1000-V001 | 1 | 7 | 7/01/2016 | 4 |
| B1000-V001 | 1 | 8 | 8/01/2016 | 8 |
| B1000-V001 | 1 | 9 | 9/01/2016 | 17 |
| B1000-V001 | 1 | 10 | 10/01/2016 | 5 |
| B1000-X123 | 5 | 1 | 1/01/2016 | 2 |
| B1000-X123 | 5 | 2 | 2/01/2016 | 8 |
| B1000-X123 | 5 | 3 | 3/01/2016 | 4 |
| B1000-X123 | 5 | 4 | 4/01/2016 | 5 |
| B1000-X123 | 5 | 5 | 5/01/2016 | 7 |
| B1000-P789 | 3 | 1 | 1/01/2016 | 8 |
| B1000-P789 | 3 | 2 | 2/01/2016 | 7 |
| B1000-P789 | 3 | 3 | 3/01/2016 | 5 |
| B1000-P789 | 3 | 4 | 4/01/2016 | 1 |
| B1000-P789 | 3 | 5 | 5/01/2016 | 4 |
+--------------+--------+---------------+-----------------+----------------+
私は、次の結果を生成するための最速の方法をしたい...
+--------------+--------+---------------+-----------------+----------------+
| EQUIPMENT_ID | CML_ID | INSPECTION_NO | INSPECTION_DATE | WALL_THICKNESS |
| B1000-V001 | 1 | 10 | 10/01/2016 | 5 |
| B1000-P789 | 3 | 5 | 5/01/2016 | 4 |
| B1000-X123 | 5 | 5 | 5/01/2016 | 7 |
+--------------+--------+---------------+-----------------+----------------+
すなわちGROUP BY EQUIPMENT_ID 、CML_IDを返し、常に最大検査番号に関連付けられたレコードを返します。
http://stackoverflow.com/questions/3491329/group-by-with-maxdate?noredirect=1&lq=1これは必要なものです。 –
@Ashokよろしくお願いいたします。この問題には、ここでは多くの良い解決策があります。 – Josh
[_Groupwise max problem_](https://mariadb.com/kb/en/mariadb/groupwise-max-in-mariadb/)のようなソムズ –