You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何对货币ID配对表去重?SQL语句优化求助

货币配对去重SQL解决方案

修改后的SQL语句如下:

with 
    cte_currencies as (
        select 'GBP' as CurrencyId union select 'USD' union select 'DKK' union select 'GBX'
    ), cte_combined_crossings as (
        select b.CurrencyId as baseCurrencyId, q.CurrencyId as QuoteCurrencyId 
        from cte_currencies b cross join cte_currencies q 
        where b.CurrencyId < q.CurrencyId
    )

select * from cte_combined_crossings

实现思路

把原SQL的过滤条件从not b.CurrencyId=q.CurrencyId替换成b.CurrencyId < q.CurrencyId,通过字典序比较货币ID,只保留基准货币ID字典序小于报价货币ID的配对,自动剔除DKK/GBP与GBP/DKK这类双向重复的条目,输出结果完全匹配目标表需求。

内容的提问来源于stack exchange,提问作者Liam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 21:55:15