Calculating new attribute based on condition in QGIS 3 Field Calculator

In your query you forgot to include the upper edge for your range of values. It is possible with using an AND-Operator.

So, try:

CASE
   WHEN "HHO_mean" > 5.7 AND "HHO_mean" <= 6.4 THEN 1
   WHEN "HHO_mean" > 6.4 AND "HHO_mean" <= 7.1 THEN 2
   WHEN "HHO_mean" > 7.1 AND "HHO_mean" <= 8.0 THEN 3
   WHEN "HHO_mean" > 8.0 AND "HHO_mean" <= 10 THEN 4
   WHEN "HHO_mean" > 10 THEN 5
   ELSE 0
END

The same issue appears in if(), therefore it has to be if("HHO_mean" > 5.7 and "HHO_mean" < 6.4, '1', ....

Nore: As far as I know the BETWEEN-Operator unfortunately is not implemented in QGIS's Field Calculator.


References:

  • SQL Comparison operator

the order of the condition check is value_if_true then value_if_false

so in your second test, it should be (note the >= instead of > on the first condition):

If( "HHO_mean" <= 5.7, '0', if( "HHO_mean" <= 6.4, '1', if( "HHO_mean" <= 7.1, '2', if( "HHO_mean" <= 8.0, '3', if( "HHO_mean" <= 10, '4', '5')))))