由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - SQL select one value column for each distinct value another (转载)
相关主题
SQL copy a table into a new table and add a new columnHow to split a column into several rows?
SQL find distinct values in large table请问sql 有条件性的select columns
谁能帮我看看这个Insert语句要怎么改一下?菜鸟问题,急
请教一个SQL的问题mysql mapping and insert question
help about SQL for ACCESS请教一个SQL Server的面试题
ask for help with a simple query!!!SQL 2008 Group By Question
sql 请教sql 题目求助
Access 里面两个 column不一样的table 能combine 到一起吗?请教一个query 优化的问题(filter keyword)
相关话题的讨论汇总
话题: sql话题: tom话题: bill话题: value话题: distinct
进入Database版参与讨论
1 (共1页)
l******9
发帖数: 579
1
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: SQL select one value column for each distinct value another col
发信站: BBS 未名空间站 (Fri Jun 27 10:29:25 2014, 美东)
On SQL server 2008 R2, I would like to select one value of a column for each
distinct value of another column.
e.g.
name id_num
Tom 53
Tom 60
Tom 27
Jane 16
Jane 16
Bill 97
Bill 83
I need to get one id_num for each distinct name, such as
name id_num
Tom 27
Jane 16
Bill 97
For each name, the id_num can be randomly picked up as long as it is
associated with the name.
For example, for Bill, I can pick up 97 or 83. Either one is ok.
I do know how to write the SQL query.
Thanks
a**d
发帖数: 4285
2
刚查的,周五下午,做题为找工作准备。
select col1, col2
from
(
select col1, col2,
ROW_NUMBER() over (partition by col1 order by newid())rn
from table1
)temp_t
where rn=1

each

【在 l******9 的大作中提到】
: 【 以下文字转载自 JobHunting 讨论区 】
: 发信人: light009 (light009), 信区: JobHunting
: 标 题: SQL select one value column for each distinct value another col
: 发信站: BBS 未名空间站 (Fri Jun 27 10:29:25 2014, 美东)
: On SQL server 2008 R2, I would like to select one value of a column for each
: distinct value of another column.
: e.g.
: name id_num
: Tom 53
: Tom 60

1 (共1页)
进入Database版参与讨论
相关主题
请教一个query 优化的问题(filter keyword)help about SQL for ACCESS
sort two same tables SQL but different resultsask for help with a simple query!!!
SQL combine two columns from two different tables no shared (转载)sql 请教
求助:如何ColumName 作为变量放入queryAccess 里面两个 column不一样的table 能combine 到一起吗?
SQL copy a table into a new table and add a new columnHow to split a column into several rows?
SQL find distinct values in large table请问sql 有条件性的select columns
谁能帮我看看这个Insert语句要怎么改一下?菜鸟问题,急
请教一个SQL的问题mysql mapping and insert question
相关话题的讨论汇总
话题: sql话题: tom话题: bill话题: value话题: distinct