gpt4 book ai didi

sql - SQL 中的替换和分组依据

转载 作者:行者123 更新时间:2023-12-04 06:49:37 25 4
gpt4 key购买 nike

嗨,我想按已替换字符但同时保留原始值的字段对我的结果进行分组。

这就是我所拥有的,但我需要在不更改结果的情况下返回原始 URL 值。

select Count(ID) as TotalClicks, Replace(URL, '/', '') as DistinctURL
from email_click_throughs
where emailid = @ID
group by Replace(URL, '/', '')
order by TotalClicks desc

最佳答案

这将为您提供您所描述的内容,但它使“替换(URL ...”上的分组变得多余,所以我可能会误解:

select Count(ID) as TotalClicks, URL as DistinctURL
from email_click_throughs
where emailid = @ID
group by Replace(URL, '/', ''), URL
order by TotalClicks desc

如果您只想取回一个 URL,即使在删除 '/' 后两个 URL 相同,您可以执行类似的操作
select Count(ID) as TotalClicks, Max(URL) as DistinctURL 
from email_click_throughs
where emailid = @ID group by Replace(URL, '/', '')
order by TotalClicks desc

但是您无法控制哪些“匹配”被丢弃。

关于sql - SQL 中的替换和分组依据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3313783/

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