请问SQL SERVER里的SQL如何去重重复列?

请问SQL SERVER里的SQL如何去重重复列?,第1张

select  from table1 a 
where  not exists(select 1 from table1 where col2=acol2 and col1<aCOL1)
 结果
COL1  COL2       COl3
1     abc        10     
3     xyz        10        
4     ijik       9           
  
  如果要显示列2则修改 col1<aCOL1 为col1>aCOL1

你的d表,a表和b表的关联字段在做join之前要保证唯一性

比如
left join (select distinct bizArea,cntNo from crm_contractbaseinfo) a on ccrtNO=acntNo

先把表1里面重复数据去掉,然后再连接表2。
select addr,rem from
(SELECT DISTINCT pro,addr from 表1 ) v1,表2
where v1pro = 表2pro

select table1name,table2
from
table1,table2 where table1userid=table2userid and table2id in
(select min(id) as id from table1,table2 where table1userid=table2userid)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13401738.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-29
下一篇 2023-07-29

发表评论

登录后才能评论

评论列表(0条)

保存