python 2019-01-02 09:09:15 Gold 454
使用此(运行缓慢)查询:
(我无法在数据浏览器上与我的主要用户单次/交叉登录,因此匿名登录)
-- insert your user id here:
declare @uid int = 7505395
-- get all badges of all users
select Name, Date, [Gold/Silver/Else], [Row#] from (
SELECT Name,
Date,
userId,
case when class = 1 then 'Gold'
when class = 2 then 'Silver'
when class = 3 then 'Bronze'
else convert(varchar(10), class)
end as 'Gold/Silver/Else',
ROW_NUMBER() OVER(PARTITION BY name, class ORDER BY date ASC) AS Row#
FROM badges
WHERE 1 = 1
-- you can restrict this further, f.e. for looking only by gold badges
-- and Class = 1 -- gold == 1, silver == 2, bronze == 3
-- -- or for certain named badges
-- and name like 'python%'
) as tmp
where userID = @uid
ORDER by name asc, Date asc
(按原样查询给了我所有的徽章,有多少在我之前得到它,并且必须对所有可能的徽章进行排序)
问题:
我尝试 CTE(只有错误,没有工作)并且我的 sql 技能生疏了 - 如何加速这个查询?