Search code examples
sqlqgis

Finding the right SQL expression for a table of attributes search in QGIS


I need to do a search in the table of attributes in QGIS. Translating from French, so the administrative territories might not be familiar to you, but hopefully the code needed will be. Basically I need to look for an IRIS (type of territory, column name : "IRIS_TYP") of which the type is 'A' or 'D' (contained in the "IRIS_TYP" column) where the name of the commune is 'Braye' (name of column "NOM_COM") and which has more than 100 logements (name of column "P14_LOG").

I was thinking of something like: 'A' and 'D' in "IRIS_TYP" in NOM_COM('Braye') > "P14_LOG" but obviously this hasn't worked.


Solution

  • In your QGIS using the DB manager tool you could use the SQL windows and type a query as

      select * from your_table  
      where IRIS_TYP IN  ('A', 'D' ) 
      AND commune ='Braye'
      HAVING count(logements) >100
    

    set the check mark "load the result as a new layer"

    and press load now