Skip to main content
deleted 1 character in body
Source Link
J.R
  • 18.3k
  • 2
  • 25
  • 57

If you created a virtual field (Virtual_1) using a CASE statement you may use the case statement in your SQL query

In the below exemple I create a virtual field (Virtual_1) using the following :

CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END 

To use this Virtual field in a Virtual layer I could just use the following SQL statement where the virtual field is replaced by the CASE expression:

SELECT DISTINCT (CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END) AS Virtual_1 FROM Admin_0_polygons 

In the below picture you can see the original table with the virtual field and the Virtual layer next to it.

enter image description here

The same principle will work with any expressionfonction that the QGIS expressionSQLite/SpatiaLite engine could evaluate including on the geometry if needed

If you created a virtual field (Virtual_1) using a CASE statement you may use the case statement in your SQL query

In the below exemple I create a virtual field (Virtual_1) using the following :

CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END 

To use this Virtual field in a Virtual layer I could just use the following SQL statement where the virtual field is replaced by the CASE expression:

SELECT DISTINCT (CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END) AS Virtual_1 FROM Admin_0_polygons 

In the below picture you can see the original table with the virtual field and the Virtual layer next to it.

enter image description here

The same principle will work with any expression that the QGIS expression engine could evaluate including the geometry if needed

If you created a virtual field (Virtual_1) using a CASE statement you may use the case statement in your SQL query

In the below exemple I create a virtual field (Virtual_1) using the following :

CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END 

To use this Virtual field in a Virtual layer I could just use the following SQL statement where the virtual field is replaced by the CASE expression:

SELECT DISTINCT (CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END) AS Virtual_1 FROM Admin_0_polygons 

In the below picture you can see the original table with the virtual field and the Virtual layer next to it.

enter image description here

The same principle will work with any fonction that SQLite/SpatiaLite engine could evaluate including on the geometry if needed

added 33 characters in body
Source Link
J.R
  • 18.3k
  • 2
  • 25
  • 57

If you created a virtual field (Virtual_1) using a CASE statement you may use the case statement in your SQL query

In the below exemple I create a virtual field (Virtual_1) using the following :

CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END 

To use this Virtual field in a Virtual layer I could just use the following SQL statement where the virtual field is replaced by the CASE expression:

SELECT DISTINCT (CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END) AS Virtual_1 FROM Admin_0_polygons 

In the below picture you can see the original table with the virtual field and the Virtual layer next to it.

enter image description here

The same principle will work with any expression that the QGIS expression engine could evaluate including the geometry if needed

If you created a virtual field (Virtual_1) using a CASE statement you may use the case statement in your SQL query

In the below exemple I create a virtual field (Virtual_1) using the following :

CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END 

To use this Virtual field in a Virtual layer I could just use the following SQL statement where the virtual field is replaced by the CASE expression:

SELECT DISTINCT (CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END) AS Virtual_1 FROM Admin_0_polygons 

In the below picture you can see the original table with the virtual field and the Virtual layer next to it.

enter image description here

The same principle will work with any expression that the QGIS expression engine could evaluate

If you created a virtual field (Virtual_1) using a CASE statement you may use the case statement in your SQL query

In the below exemple I create a virtual field (Virtual_1) using the following :

CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END 

To use this Virtual field in a Virtual layer I could just use the following SQL statement where the virtual field is replaced by the CASE expression:

SELECT DISTINCT (CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END) AS Virtual_1 FROM Admin_0_polygons 

In the below picture you can see the original table with the virtual field and the Virtual layer next to it.

enter image description here

The same principle will work with any expression that the QGIS expression engine could evaluate including the geometry if needed

Source Link
J.R
  • 18.3k
  • 2
  • 25
  • 57

If you created a virtual field (Virtual_1) using a CASE statement you may use the case statement in your SQL query

In the below exemple I create a virtual field (Virtual_1) using the following :

CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END 

To use this Virtual field in a Virtual layer I could just use the following SQL statement where the virtual field is replaced by the CASE expression:

SELECT DISTINCT (CASE WHEN "continent" IN ( 'North America' , 'South America' ) THEN 'On the Left' WHEN "continent" IN ( 'Africa' , 'Asia' , 'Europe' ) THEN 'On the Right' WHEN "continent" = 'Antarctica' THEN 'A the Bottom' ELSE 'Other' END) AS Virtual_1 FROM Admin_0_polygons 

In the below picture you can see the original table with the virtual field and the Virtual layer next to it.

enter image description here

The same principle will work with any expression that the QGIS expression engine could evaluate