我在编写查询时遇到了一个问题,即在表中查找重复的成员。我试图用样本表和数据简化问题。
CREATE TABLE MYTABLE (
S_ID VARCHAR2(10),
PARAM VARCHAR2(10),
VALUE VARCHAR2(10)
);
INSERT INTO MYTABLE (S_ID, PARAM, VALUE) VALUES ('1', 'NAME', 'A');
INSERT INTO MYTABLE (S_ID, PARAM, VALUE) VALUES ('1', 'AGE', '15');
INSERT INTO MYTABLE (S_ID, PARAM, VALUE) VALUES ('1', 'SEX', 'M');
INSERT INTO MYTABLE (S_ID, PARAM, VALUE) VALUES ('2', 'NAME', 'B');
INSERT INTO MYTABLE (S_ID, PARAM, VALUE) VALUES ('2', 'AGE', '16');
INSERT INTO MYTABLE (S_ID, PARAM, VALUE) VALUES ('2', 'SEX', 'M');
INSERT INTO MYTABLE (S_ID, PARAM, VALUE) VALUES ('3', 'NAME', 'A');
INSERT INTO MYTABLE (S_ID, PARAM, VALUE) VALUES ('3', 'AGE', '15');
INSERT INTO MYTABLE (S_ID, PARAM, VALUE) VALUES ('3', 'SEX', 'M');
此处S_ID 1和3的项目相同。
答案 0 :(得分:1)
这是在一个字段中查找重复值的简便方法:
SELECT fieldName FROM TableName
GROUP BY FieldName
HAVING COUNT(*) > 1
答案 1 :(得分:1)
select colname, count(colname) from TableName
Group by colname Having (count(colname) > 1)