'Get a list of the last line of progress of each item sub-reference
I have two table a and b. In the table there are: unique id for the article, sref1: for the sub-reference of the article and shortname of the article. In table b, it's she who manages the completeness of the article with a history. There is a unique identifier, the completenessProgression and completenessObject_id which refers to the identifier of table a.
Last row of table b in my progress field. And in the same query it would take a sort without duplicate of the concat ("shortname", "-", "sub-reference"). So have in return for my request the for each article with its sub-reference the last progression to save.
Currently I know how to retrieve the last value of the progress for a specific article :
SELECT oo_id, completenessProgression, completenessObject__id
FROM object_20 WHERE object_20.completenessObject__id=171423
ORDER BY object_20.oo_id DESC LIMIT 1;
I also know how to retrieve articles by name and sub-reference1 with a GROUP BY :
SELECT object_20.oo_id AS Id, object_20.completenessObject__id AS id2,
object_20.completenessProgression AS Progress,
object_1.CSubRef1 AS Color, object_1.shortname AS Name
FROM object_20 INNER JOIN object_1
ON object_1.oo_id = object_20.completenessObject__id
WHERE object_20.completenessProgression >= 80
GROUP BY CONCAT(object_1.CSubRef1, ' ',object_1.shortname);
But when I add in my where clause a completenessProgression> 80. It does not take the last values of my completeness for each article by name and under reference.
I have tested with various sub-request but I cannot get something correct. I can only use queries, no script, no trigger.
http://sqlfiddle.com/#!9/9a51d/1
+------------------------------------+
| Results Completeness > 80 |
+-----+----------+--------+----------+
| Id | Name | Color | Progress |
+-----+----------+--------+----------+
| 2 | Armand | Jaune | 98 |
+-----+----------+--------+----------+
| 4 | Herbert | Bleu | 100 |
+-----+----------+--------+----------+
edit 30 November 2021
The problem is that in my case I have a sub-reference 2 which is the size and I don't want this value because the progression is similar from one sub-reference 2 to another.
And the problem is there, I have as many lines as there are sizes while I only want one line per CSubRef1 and not one line per CSubRef2
If I'm not clear, I can make a screen of my current output. that's why in my case I made a:
GROUP BY CONCAT(object_1.CSubRef1, ' ',object_1.shortname);
but it doesn't work the way i would like
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
