当前位置: 代码迷 >> Sql Server >> 求Query解决思路
  详细解决方案

求Query解决思路

热度:81   发布时间:2016-04-27 11:02:41.0
求Query

有这样一张表
SQL code
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来。



------解决方案--------------------
SQL code
SELECT a.* FROM dbtest a INNER JOIN dbtest b ON a.oname=b.onameWHERE a.pid<>b.pid/*OID         Oname                                                                                                PID         Com----------- ---------------------------------------------------------------- ----------- ----------------------------------------------------------------12351       DFGFG                                                                                                365         EEZZXXFF12350       DFGFG                                                                                                362         CCZZXXDD12356       XXCVD                                                                                                364         GGZZXXV12355       XXCVD                                                                                                362         WWZZXXD(4 行受影响)*/
  相关解决方案