I need to grab only 1 value for each unique componentID (so the top 2 rows result from the image would be the perfect result).
SELECT cs.ID ,AvgStatisticData ,cs.ComponentID
FROM PortEvidence pe
JOIN ComponentStatus cs ON cs.ID=pe.ComponentStatusID
JOIN Component c ON c.ComponentID= cs.ComponentID
WHERE c.ComponentType = 48
ORDER BY cs.ID DESC
1条答案
按热度按时间eoigrqb61#
All untested but the basic concepts are there...
Modern approach to least:
In each of the below I use a common table expression (CTE) just so I don't have to deal with repeating the query or thinking through what elemnts would be needed...
USing a window function:
Using subquery inner join
Or using more modern approach assuming SQL Server using table value functions and cross apply
OR use a coorlated subquery and exists.