这里使用CASE WHEN THEN最合适不过了!
SELECT (CASE
WHEN RW >=3 THEN 3
WHEN RW >= 1 AND RW < 3 THEN 2
WHEN RW < 1 THEN 1
ELSE 0
END) FLAG
FROM TABLE_NAME WHERE TO_CHAR(TJYF,'YYYY-MM-DD') >= '2020-01-01'
GROUP BY
(CASE
WHEN RW >=3 THEN 3
WHEN RW >= 1 AND RW < 3 THEN 2
WHEN RW < 1 THEN 1
ELSE 0
END)