繁体   English   中英

sql结合两个不同的行条目相同

[英]sql combining two distinct row entries as the same

我的数据库中有两种截然不同的运动类型,它们含义相同

短跑赛车1,短跑赛车2

我需要专门为Dash Racing做一个客户计数,我希望sql将破折号1和2的客户计数合并起来,而不必在之后手动添加。

有办法吗?

代码如下:

select  Sport ,
        count(distinct customerID ) 'CustCount' ,
        sum(Stake) 'TotalStake' ,
        sum(Return) 'TotalReturn'
from    table1
where   sport in ('dash horse racing' , 'dash horse racing 2')
group by Sport

它返回类似于此表:

Sport   -----------------------   CustCount-------- TotalStake  --------    TotalReturn
dash Horse Racing 2
dash Horse Racing 1

但是我想结合VS Racing 1和2,创建一个新的结合运动'VS Horse Racing',得到一张像这样的表:

*Sport ----------- CustCount---------TotalStake----------TotalReturn*

*dash Horse Racing*

任何帮助,将不胜感激。 谢谢。

只需选择所需的文本,然后取消分组依据

select  'dash horse racing' as Sport ,
        count(distinct customerID ) 'CustCount' ,
        sum(Stake) 'TotalStake' ,
        sum(Return) 'TotalReturn'
from    table1
where   sport in ('dash horse racing' , 'dash horse racing 2')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM