求教,
如何找到表中,编号重复,但内容不同的数据。
表如下:
-

-- ---------------------------
-- Table structure for `teststudents`
-- ----------------------------
DROP TABLE IF EXISTS `teststudents`;
CREATE TABLE `teststudents` (
`name` varchar(30) DEFAULT NULL,
`code` varchar(30) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of teststudents
-- ----------------------------
INSERT INTO `teststudents` VALUES ('王小二', '200101');
INSERT INTO `teststudents` VALUES ('李小二', '200101');
INSERT INTO `teststudents` VALUES ('王大锤', '201512');
谢谢!
------解决思路----------------------
select a.* from #tb a join #tb b on a.code =b.code and a.name <>b.name ?
------解决思路----------------------
SELECT *
FROM teststudents T1
WHERE EXISTS(SELECT 1 FROM teststudents T2 WHERE T1.code=T2.code AND T1.name<>T2.name)
------解决思路----------------------
Declare @TmpTest Table(
Name NVarchar(100),
Code Int)
INSERT INTO @TmpTest VALUES ('王小二', '200101');
INSERT INTO @TmpTest VALUES ('李小二', '200101');
INSERT INTO @TmpTest VALUES ('王大锤', '201512');
Select * From @TmpTest Where Code In (Select Code From @TmpTest Group By Code Having COUNT(1) > 1)
Order By Code