Question: I have a website for a project that needs to summarize all of the budget categories in one column.

For example I have a column which contains:

Categories:

Water,Electricity,Gas,Rentals,Hospital Fees,Medicine,Personal Care,Fitness,

I want to select the sum of

water,electricity,gas,rentals

and name it as utility bills.

Same as sum of

hospital fees, medicine, personal care, fitness

as healthcare.

What sql statement should i use?

Any help will be appreciated

Answer: 
You'd have some other table perhaps, or another column on this table, that maps the specific bills to a general group or category

You would then run a query like (if you put the category group in the main table)

```
SELECT categorygroup, sum(amount)
FROM bills
GROUP BY categorygroup

```

Or (if you have a separate table you join in)

```
SELECT bcg.categorygroup, sum(amount)
FROM bills b INNER JOIN billcategorygroups bcg ON b.category=bcg.category
GROUP BY bcg.categorygroup

```

You would then maintain the tables, either like (category in main table style):

```
Bills
Category, CategoryGroup, Amount
---
Electricity, Utility, 123
Water, Utility, 456

```

Or (separate table to map categories with groups style)

```
BillCategoryGroups
Category, CategoryGroup
---
Water, Utility
Electricity, Utility

```

Etc

Something has to map electricity -> utility, water -> utility etc. I'd probably have a separate table because it is easy to reorganize. If you decide that Cellular is no longer Utility but instead Personal then just changing it in the mapping table will change all the reporting. It also helps prevent typos and data entry errors affecting reports - if you use the single table route and put even one Electricity bill down as Utitily then it gets its own line on the report. Adding new categories is easy with a separate table too. All these things can be done with single table and big update statements etc but we have "normalization" of data for good reasons
You may use conditional aggregation. Like

```sql
SELECT project,
       SUM(CASE WHEN category IN ('water','electricity','gas','rentals')
                THEN spent
                ELSE 0
                END) AS bills,
       SUM(CASE WHEN category IN ('hospital fees','medicine','personal care','fitness')
                THEN spent
                ELSE 0
                END) AS healthcare
FROM datatable
GROUP BY project;

```

But the data normalization is the best option. All categories must be moved to separate table. See [Caius Jard](https://stackoverflow.com/users/1410664/caius-jard)'s answer.