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.
The same principle will work with any expressionfonction that the QGIS expressionSQLite/SpatiaLite engine could evaluate including on the geometry if needed
