gpt4 book ai didi

sql - 简单的 MS SQL 计数问题

转载 作者:行者123 更新时间:2023-12-01 11:07:59 24 4
gpt4 key购买 nike

我有这个SQL

DECLARE @url varchar(100)
SET @url = 'http://mysite.com/%'

SELECT
[UserSessionSequenceID]
,[SiteID]
,[Referer]
,[Timestamp]
,ROW_NUMBER() over (PARTITION BY [Referer] ORDER BY referer DESC) AS sort
FROM [tblSequence]
WHERE [Referer] IS NOT NULL AND [Referer] NOT LIKE @url AND siteID = 15

想要计算唯一引用者 - 问题是此 SQL 返回所有匹配项并一一计算。我只想要每个唯一引荐来源网址的计数(并且仍然用类似的方式排除@url)。

怎么做?

最佳答案

SELECT
[Referer], Count([Referer]) as RefCount
FROM [tblSequence]
WHERE [Referer] IS NOT NULL AND [Referer] NOT LIKE @url AND siteID = 15
GROUP BY [Referer]

恢复订单(如果确实需要)取决于您的具体要求。

关于sql - 简单的 MS SQL 计数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3396707/

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