www.1862.net > sql 分组去重问题求助

sql 分组去重问题求助

可以这样 select * from table a where a.number = (select min(b.number) from table b where a.group = b.group)

你要怎么去重,是按天,还是按照完全的时间(时分秒)来去重。 去重以后要达到什么效果,你的需求说的不明确,也就没办法操作,而且还要说明是什么数据库,oracle和sqlserver的方法也是不同的。

用分析函数row_number() over (partition by ... order by ...)给记录进行分组编号,按人员id和考勤日期进行分组(如果考勤日期带时分秒,需先截断到日),按时间升序排序;这样,就得到人员ID在同一考勤日期下的编号值(编号值是从1开始的),然后...

delete afrom 数据_1 awhere exists( select * from 数据_1 b where b.[会员名]=a.[会员名] and b.[创建时间]=a.[创建时间] and b.[状态]a.[状态]) and a.[状态]='否'

使用in或者exists 但是相对来说,使用in的速度慢,可以尝试使用exist(如果数据多,会更明显的感觉到,数据极少,几乎没差别) 1。使用in SELECT service, name, note FROM table01 WHERE service NOT IN (SELECT service FROM table02) 2。使用...

select * from temp_01 where id in(select id from temp_01 where to_char(op_itme,'yyyy-mm') between '201311'and '201407'group by id having count(*)>1),如果没有理解错的话,这个应该就可以了!

select 地市, sum(isnull(case when 故障类型='故障a' then 1 else 0 end,0))+ sum(isnull(case when 故障类型='故障b' then 1 else 0 end,0))+ sum(isnull(case when 故障类型='故障c' then 1 else 0 end,0)) 维修总数, sum(case when 故障类型...

一般是这样操作的 查询重复井号: select jh from 表 group by jh having conunt(jh) > 1 查询有重复井号的信息信息 select * from 表 where jh in ( select jh from 表 group by jh having conunt(jh) > 1 ) order by jh

select 时间,count(*) from (select distinct 时间,用户名 from 表名) t group by 时间

I believe you cannot do it with distinct, but you may bypass it as in the example below, data t1; do i=1 to 20; a=ceil(ranuni(127)*5); output; end; keep a; run; proc print;run; proc sql; create table t2 as select a as b, min(N)...

网站地图

All rights reserved Powered by www.1862.net

copyright ©right 2010-2021。
www.1862.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com