1. select a.* from tb a inner join tb b on a.名称=b.名称 and a.类型=b.类型 and a.说明<>b.说明 2. select a.* from tb a inner join tb b on a.名称=b.名称 and a.类型<>b.类型 and a.说明=b.说明 3. select a.* from tb a inner join tb b on a.名称<>b.名称 and a.类型=b.类型 and a.说明=b.说明
如果标识唯一: select * from tb a where 标识=(select min(标识) from tb where 名称=a.名称 and 类型=a.类型 and 说明=a.说明 )
select distinct 名称,类型,说明 from tb
Happiness(乐乐)是对的,非常感谢哦。
: 同意 Happiness(乐乐)
create table tb(標識 int,名稱 varchar(10), 類型 varchar(10), 說明 varchar(1), 城市 varchar(10)) Insert into tb select '1','a','11','y','南京' union all select '2','b','12','n','北京' union all select '3','c','11','y','南京' union all select '4','b','12','n','上海' union all select '5','a','11','y','天津' union all select '6','c','12','n','廣州' union all select '7','b','13','y','北京' union all select '8','a','11','n','上海'select * from tb1. select distinct a.* from tb a inner join tb b on a.名稱=b.名稱 and a.類型=b.類型 and a.說明<>b.說明 order by a.標識 --結果 -------------------------------- 1 a 11 y 南京 5 a 11 y 天津 8 a 11 n 上海2. select a.* from tb a inner join tb b on a.名稱=b.名稱 and a.類型<>b.類型 and a.說明=b.說明 order by a.標識 --結果 -------------------------------- 沒有符合條件的記錄3. select distinct a.* from tb a inner join tb b on a.名稱<>b.名稱 and a.類型=b.類型 and a.說明=b.說明 order by a.標識 --結果 -------------------------------- 1 a 11 y 南京 2 b 12 n 北京 3 c 11 y 南京 4 b 12 n 上海 5 a 11 y 天津 6 c 12 n 廣州
select a.* from tb a inner join tb b
on a.名称=b.名称 and a.类型=b.类型 and a.说明<>b.说明
2.
select a.* from tb a inner join tb b
on a.名称=b.名称 and a.类型<>b.类型 and a.说明=b.说明
3.
select a.* from tb a inner join tb b
on a.名称<>b.名称 and a.类型=b.类型 and a.说明=b.说明
select * from tb a
where 标识=(select min(标识) from tb where 名称=a.名称 and 类型=a.类型 and 说明=a.说明 )
Insert into tb
select '1','a','11','y','南京'
union all select '2','b','12','n','北京'
union all select '3','c','11','y','南京'
union all select '4','b','12','n','上海'
union all select '5','a','11','y','天津'
union all select '6','c','12','n','廣州'
union all select '7','b','13','y','北京'
union all select '8','a','11','n','上海'select * from tb1.
select distinct a.* from tb a inner join tb b
on a.名稱=b.名稱 and a.類型=b.類型 and a.說明<>b.說明 order by a.標識
--結果
--------------------------------
1 a 11 y 南京
5 a 11 y 天津
8 a 11 n 上海2.
select a.* from tb a inner join tb b
on a.名稱=b.名稱 and a.類型<>b.類型 and a.說明=b.說明 order by a.標識
--結果
--------------------------------
沒有符合條件的記錄3.
select distinct a.* from tb a inner join tb b
on a.名稱<>b.名稱 and a.類型=b.類型 and a.說明=b.說明 order by a.標識
--結果
--------------------------------
1 a 11 y 南京
2 b 12 n 北京
3 c 11 y 南京
4 b 12 n 上海
5 a 11 y 天津
6 c 12 n 廣州