1

I have a dataset with concentrations of copper from different stations taken over several years. I would like to show only the highest concentration "mikromolar" for each station "STATN", and I tried using the

maximum("mikromolar", group_by:="STATN")

in the query builder, but all I get is error message when executing the query:

OGR[3] error 1: SQL Expression Parsing Error: syntax error, unexpected $undefined, expecting ')'. Occurred around : maximum("mikromolar", group_by:="STATN")

How do I do this?

1
  • An error occurred when executing the query. The data provider said: OGR[3] error 1: SQL Expression Parsing Error: syntax error, unexpected $undefined, expecting ')'. Occurred around : maximum("mikromolar", group_by:="STATN")
    – Linda
    Aug 4, 2020 at 12:31

1 Answer 1

2

If you use your expression in the select by expression, QGIS will examine the result as a logical value( 0 - False, non-zero - True).

I can give you two receipts to select max concentration at each station.

  1. Add a virtual column to your table with the maximum value grouped by the station name. From the attribute table select Open field calculator and enter the followings:

enter image description here

Now you have max_cop column filled with the maximum of the station. In the a next step you can select those rows where the "micromolar" column is equal to the "max_cop" column. If you change the values of "mikromolar" the virtual column will be updated if you close and open the attribute table.

  1. Using the DB Manager module, you can use SQL to select even from shape files. Your SQL statement should be

    SELECT STATN, max(mikrobar) FROM your_table GROUP BY STATN;

This way you get a new attribute table only layer in your project if you select Load as new layer checkbox.

2
  • I think your SQL query lacks of DISTINCT
    – Taras
    Jul 31, 2020 at 9:44
  • @Taras, no group by will do it.
    – Zoltan
    Jul 31, 2020 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.