gpt4 book ai didi

带别名的 SQL Rollup

转载 作者:行者123 更新时间:2023-11-29 12:56:56 26 4
gpt4 key购买 nike

我有这个sql查询

Select 
Case
When transfer.trf_type = 'c' then 'Transfer to own card'
When transfer.trf_type = 'o' then 'Transfer to own account'
When transfer.trf_type = 'I' then 'Transfer to a domestic bank'
When transfer.trf_type = 'b' then 'Transfer to another AIIB Customer'
End As Type ,
Count(transfer.trf_type) As total,
Sum (transfer.amount*currency.rate) AS totalSum
From transfer
Inner Join currency on transfer.currency = currency.currency
Where transfer.to_card IS null
Group By Rollup(Type)

它给了我结果集的总和,但有一个空格。

我希望汇总行以特定别名出现,例如:“资金转账总额”。我该如何实现?

这是我的查询结果,我需要在最后一行加上总计

enter image description here

谢谢

最佳答案

试试这个

   with grpSum as (Select
Case
When transfer.trf_type = 'c' then 'Transfer to own card'
When transfer.trf_type = 'o' then 'Transfer to own account'
When transfer.trf_type = 'I' then 'Transfer to a domestic bank'
When transfer.trf_type = 'b' then 'Transfer to another AIIB Customer'
End As Type ,
Count(transfer.trf_type) As total,
Sum (transfer.amount*currency.rate) AS totalSum
From transfer
Inner Join currency on transfer.currency = currency.currency
Where transfer.to_card IS null
Group By ROLLUP(Type))
select COALESCE(Type,'Total found transfers'),total,totalSum from grpSum

关于带别名的 SQL Rollup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40867193/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com