当前位置: 代码迷 >> Sql Server >> 求Query,该如何解决
  详细解决方案

求Query,该如何解决

热度:75   发布时间:2016-04-25 00:02:34.0
求Query

有这样一张表
create table DBTest (OID int,Oname nvarchar(100),PID int,Com nvarchar(100))
insert into DBTest values ('12345','ABC','364','CZZXXCC')
insert into DBTest values ('12346','ABC','364','EZZXXEE')
insert into DBTest values ('12350','DFGFG','362','CCZZXXDD')
insert into DBTest values ('12351','DFGFG','365','EEZZXXFF')
insert into DBTest values ('12355','XXCVD','362','WWZZXXD')
insert into DBTest values ('12356','XXCVD','364','GGZZXXV')


如何Oname一样,但PID不一样的OID来。


------解决方案--------------------

SELECT a.* FROM dbtest a INNER JOIN dbtest b ON a.oname=b.oname
WHERE a.pid<>b.pid

/*
OID         Oname                                                                                                PID         Com
----------- ---------------------------------------------------------------- ----------- ----------------------------------------------------------------
12351       DFGFG                                                                                                365         EEZZXXFF
12350       DFGFG                                                                                                362         CCZZXXDD
12356       XXCVD                                                                                                364         GGZZXXV
12355       XXCVD                                                                                                362         WWZZXXD
  相关解决方案