我有以下有效的查询。它包括billing.transaction表中所有状态的交易总数。我需要添加另一列(第4列),其中具有特定状态(例如“有效”)的交易量,以计算每个城市中具有“有效”状态的交易总额与t_amount的比率。感谢您的支持。
先谢谢您。
`select left(t.reference_id,5) as city_code,
case when left(t.reference_id,5) = 'DE-01' then 'city1'
when left(t.reference_id,5) = 'DE-02' then 'city2'
when left(t.reference_id,5) = 'DE-03' then 'city3'
when left(t.reference_id,5) = 'DE-04' then 'city4'
when left(t.reference_id,5) = 'DE-05' then 'city5'
when left(t.reference_id,5) = 'DE-09' then 'city6'
when left(t.reference_id,5) = 'DE-11' then 'city7'
else 'city8'
end as city,
sum(e.amount) as t_amount
from billing.transaction_entry e
left join billing.transaction t on e.transaction_id = t.id
where e.amount > '0' and t.created_at > '2019-06-30' and t.created_at <
'2019-08-01' and t.type='MONTHLY_RENT'
group by left(t.reference_id,5)
order by t_amount desc;`