表 A
time vale1 value2
11:00 2 3
11:30 4 5
11:00 3 3
11:30 4 3
sql语句,得到如下结果
time vale1 value2
11:00 2 3
11:30 4 5
其实就是去掉time字段重复的记录,显示所有字段值,重复记录取哪一条都可以。
sqlserver 的DISTINCT用法是可以做到的,但是orcale里的DISTINCT用法却做不到。
各位帮帮忙,谢谢。
------解决方案--------------------
- SQL code
with t as(select '11:00' time1, '2' value1,'3' value2 from dualunion allselect '11:30' time1, '4' value1,'5' value2 from dualunion allselect '11:00' time1, '3' value1,'3' value2 from dualunion allselect '11:30' time1, '4' value1,'3' value2 from dual)select tt.time1,tt.value1,tt.value2from (select t.time1,t.value1,t.value2,row_number() over(partition by t.time1 order by t.value1) rnfrom t) ttwhere tt.rn = 1
------解决方案--------------------
借用滤重的语句也可以
- SQL code
select * from from table where rowid in ( select max(rowid) from table group by time)
------解决方案--------------------
select * from temp where rowid in (select max(rowid) from temp group by time)
------解决方案--------------------
为啥上面都写的这么麻烦呢? 这样可以么
- SQL code
select time , max(vale1), max(value2)from Agroup by time
------解决方案--------------------
用row_number()(partition by 字段 order by 字段 ) 是比较好的方法!
------解决方案--------------------
select time ,min(vale1) ,max(vale2) from table group by time
------解决方案--------------------
+1 天朝的人都喜欢拿简单的事复杂化。