Group by NAME and YEAR, categorize NAME I have a FINANCE_SOURCE table (I think it might be called a vertical table):

+-----------+------------+-------------+--------+------+
| SOURCE_ID | PROJECT_ID | SOURCE_NAME | AMOUNT | YEAR |
+-----------+------------+-------------+--------+------+
|       101 |          1 | A           |  10.00 | 2017 |
|       102 |          1 | B           |   5.00 | 2017 |
|       103 |          1 | B           |  15.00 | 2017 |
|       104 |          1 | B           |  70.00 | 2016 |
|       105 |          1 | C           |  30.00 | 2017 |
|       106 |          1 | D           |   1.00 | 2016 |
|       107 |          1 | D           |  20.00 | 2017 |
+-----------+------------+-------------+--------+------+


I want to GROUP BY the SOURCE_NAME, with a separate group for each YEAR.

And I want any record where the SOURCE is not A or B to be categorized as OTHER:

+------------+-------------+--------+------+
| PROJECT_ID | SOURCE_NAME | AMOUNT | YEAR |
+------------+-------------+--------+------+
|          1 | A           |  10.00 | 2017 |
|          1 | B           |  20.00 | 2017 |
|          1 | B           |  70.00 | 2016 |
|          1 | OTHER       |  50.00 | 2017 |
|          1 | OTHER       |   1.00 | 2016 |
+------------+-------------+--------+------+


How can I do this? Performance is important.
Add the CASE expression to the GROUP BY clause.

SELECT   PROJECT_ID,
         CASE WHEN SOURCE_NAME = 'A' THEN 'A'
              WHEN SOURCE_NAME = 'B' THEN 'B'
              ELSE 'OTHER'
         END SOURCE_NAME,
         SUM(AMOUNT) AMOUNT,
         YEAR
FROM     FINANCE_SOURCE
GROUP BY PROJECT_ID, 
         CASE WHEN SOURCE_NAME = 'A' THEN 'A'
              WHEN SOURCE_NAME = 'B' THEN 'B'
              ELSE 'OTHER'
         END,
         YEAR