【发布时间】:2015-10-13 10:29:04
【问题描述】:
myTable 如下所示:
id rDate r rName
1 41086 0.2 ax_ax03_a
1 41086 0.2 ax_ax03_a
1 41086 0.2 ax_ax03_a
1 41087 0.4 ax_ax03_a
1 41087 0.4 ax_ax03_a
2 41086 0.12 ax_ax06_a
2 41086 0.12 ax_ax06_a
2 41086 0.12 ax_ax06_a
2 41087 0.5 ax_ax06_a
2 41087 0.34 ax_ax06_a
等等
对于每个 id,我都有一组日期(需要使用 cast(rDate as DATETIME)、值 (r) 和名称进行转换。 我需要消除同时具有相同 id, rDate, r, rName 的所有输入项(重复项)。 我在想一些事情:
select id,CAST(rDate AS DATETIME) over (partition by rName, id) as rDateNew, rName from myTable
使用 sql server 2012
【问题讨论】:
-
select distinct * from mytable将选择不同的值。您是要选择不同的行还是删除重复的行? -
select distinct id,CAST(rDate AS DATETIME) over (partition by rName, id) as rDateNew, rName from myTable -
我认为您可以使用
GROUP BY消除重复项 -
有什么独特之处吗? (例如自动编号的 id)
-
行中没有独特的东西。对于相同的 id,有多个日期和值。然而,一个 id 对应于名称
标签: sql sql-server sql-server-2012 window-functions