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

如何从Stack Exchange Data Explorer(SEDE)获取用户历史显示名称?

如何从Stack Exchange Data Explorer(SEDE)获取用户历史显示名称

用户修改显示名称后,旧评论里的@提及用的是修改前的名字,无法直接对应到当前用户。比如某帖子评论里提到的@OneKitten,就是用户改名前的名称,需要批量获取这类历史名称数据。

之前尝试的SQL查询只能拿到Users表的当前字段,没有历史显示名称相关数据:

# here PK='id' and table='users'

select c.Table_Name
     , case 
       when ##PK:string?id## = c.column_name then concat(c.column_name,' (PK)') 
       else c.column_name 
       end as column_name
     , data_type
     , is_nullable
     , coalesce(CHARACTER_MAXIMUM_LENGTH
             , numeric_precision
             , datetime_precision) as [Length/precision]
 --     ,*
from INFORMATION_SCHEMA.Columns c
where c.table_name = ##table:string?posts##
order by ordinal_position

正确解决方案

SEDE里专门有UserDisplayNameHistory表,存储用户所有的显示名称变更记录。可以用以下SQL查询获取指定用户或批量用户的历史显示名称:

-- 替换下面的用户ID列表为你需要查询的用户ID
SELECT 
  udh.UserId,
  u.DisplayName AS 当前显示名称,
  udh.DisplayName AS 历史显示名称,
  udh.CreationDate AS 名称生效时间
FROM UserDisplayNameHistory udh
JOIN Users u ON udh.UserId = u.Id
-- 可以添加WHERE条件过滤特定用户,比如:
-- WHERE udh.UserId IN (123, 456, 789)
ORDER BY udh.UserId, udh.CreationDate DESC;

字段说明

  • UserDisplayNameHistory表核心字段:
    • UserId: 用户唯一ID(与Users表的Id对应)
    • DisplayName: 用户曾经使用过的显示名称
    • CreationDate: 该名称开始使用的时间
  • 关联Users表可同时获取用户当前显示名称,方便对比历史名称与当前名称的对应关系
  • 需要批量查询时,在WHERE子句里指定目标UserId列表即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 04:56:08