Thursday 21 April 2016

QGIS 3.4 feature filter maximum() does not work


I would like to filter a layer with the maximum value of field_a, grouped by field_b. I tried this expression: "field_a"= maximum ( "field_a","field_b") But it doesn't work (there are no more features in the layer). When I use this expression for Select by Expression, the features are selected. Is there a way to filter them (without selecting)?


[Edit] I want to filter a existing layer (right mouse click -> filter). I don't want to select features or to create a new layer.




Answer



The filter query (layer properties/source/provider feature filter) allows you to specify an SQL where clause. If you enter id=1 it will translate it to select * from mylayer where id=1.


From there, you can add a sub-query in this where clause to identify the IDs (or else) of interest:


field_a IN (SELECT MAX(field_a) FROM myLayer GROUP BY field_b)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...