extracting data from nested SQL
Problem:
Extract from a table the rows corresponding to the maximum value of a field of the table group denoted by a field.
Eg.
Table:
Id - Group - Val
id1 id2
2 G1 G1 1
id3
G1 0 G2 0
ID4 ID5 ID6
G3 3 G3 2
Desiderata:
Id - Group - Val
id1 2 G1 G2 0
ID4 ID5
G3 3
Solution with nested query:
SELECT Id, Group, Val
FROM table WHERE
tabella.Val
IN (SELECT MAX (Val) AS Expr1 FROM table AS
aliasTabella
WHERE (tabella.Id = aliasTabella.Id) GROUP BY
Group)) ;
0 comments:
Post a Comment