MySQL条件选择2个字段中的1个,然后按2个字段的组合进行分组

I'm a bit new to conditional statements in MySQL queries, I'm wondering if someone can help me out with the following?

I have the following table:

Company | Billing_State | Delivery_State | Revenue

How would I conditionally select the billing state if the company name equals 'XYZ' but otherwise select delivery state if not -- and then group by states, regardless of whether it's a billing state or delivery state? Let's say for the purpose of aggregating sales revenue reports by US states.

Thanks in advance.

You are looking for something like:

select if(company = 'XYZ',billing_state,delivery_state), sum(revenue)
from companies
group by if(company = 'XYZ',billing_state,delivery_state)