Account dst
123 AB
12345 AA
123 AA
789 CD
如何找出dst字段相同而account字段不相同的数据
26 个解决方案
#1
数据结构
Account dst
123 AB
12345 AA
123 AA
789 CD
如何找出dst字段相同而account字段不相同的数据
自己先顶起
Account dst
123 AB
12345 AA
123 AA
789 CD
如何找出dst字段相同而account字段不相同的数据
自己先顶起
#2
SEELCT * FROM TB T WHERE EXISTS(SELECT 1 FROM TB WHERE [DST]=T.[DST] AND Account <>T.Account )
#3
试试看
#4
/*
-- Author:SQL77--RICHIE
-- Version:V1.001 Date:2008-05-15--转Flystone
*/
-- Test Data: TB
If object_id('TB') is not null
Drop table TB
Go
Create table TB(Account int,dst varchar(2))
Go
Insert into TB
select 123,'AB' union all
select 12345,'AA' union all
select 123,'AA' union all
select 789,'CD'
Go
--Start
SELECT * FROM TB T WHERE EXISTS(SELECT 1 FROM TB WHERE [DST]=T.[DST] AND Account <>T.Account )
--Result:
/*
(所影响的行数为 4 行)
Account dst
----------- ----
12345 AA
123 AA
(所影响的行数为 2 行)
*/
--End
#5
select * from table where dst in (select dst from table group by dst having count(dst )>1) order by dst
#6
mysql的也可以吗
#7
--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB]([Account] int,[dst] varchar(2))
insert [TB]
select 123,'AB' union all
select 12345,'AA' union all
select 123,'AA' union all
select 789,'CD'
select * from [TB] t where not exists(select 1 from TB where t.Account=Account and t.dst>dst)
/*
Account dst
----------- ----
12345 AA
123 AA
789 CD
(所影响的行数为 3 行)
*/
drop table TB
#8
可能语法不同
#9
不错 好方法 up
#10
试试这个吧,
#11
性能好像不怎么样,我在mysql中执行了好久都出来数据
#12
五万多数据好像就挂了
#13
下面这句好像不行哦
#14
你加索引了没有
#15
这样查出来好像很多垃圾数据啊
#16
那你又不说清楚要什么结果,按你说的就是那个意思呀
#17
declare @t table( Account int , dst varchar(20))
insert into @t values( 123 , 'AB')
insert into @t values( 12345, 'AA')
insert into @t values( 123 , 'AA')
insert into @t values( 12345 , 'AA')
insert into @t values( 789 , 'CD')
select distinct * from @t where dst in(
select dst from @t group by dst having Count( distinct(Account)) >1)
#18
account dst
123 AA
123 AA
123 AA
123 AB
123 AC
12345 AA
123 AA
我要的结果就是:
123 AA
12345 AA
123 AA
123 AA
123 AA
123 AB
123 AC
12345 AA
123 AA
我要的结果就是:
123 AA
12345 AA
#19
自己把顶起来
#20
17楼的
这样好像数据也是有垃圾数据,在ACCOUNT 和dst两个字段都是有很多重复的
这样好像数据也是有垃圾数据,在ACCOUNT 和dst两个字段都是有很多重复的
#21
你是不是还有其他的关联字段啊
#22
整个表是有很多字段,但是我现在只要这两个字段来区分数据
#23
select distinct account ,dst from @t where dst in(
select dst from @t group by dst having Count( distinct(Account)) >1)
修改一下17楼的试试
#24
#25
学习来了
#26
if object_id('[TB]') is not null drop table [TB]
create table [TB]([Account] int,[dst] varchar(2))
insert into [TB] values(123,'aa')
insert into [TB] values(123,'aa')
insert into [TB] values(123,'bb')
insert into [TB] values(123,'bb')
insert into [TB] values(1234,'bb')
insert into [TB] values(123,'cc')
insert into [TB] values(1234,'dd')
insert into [TB] values(1234,'aa')
insert into [TB] values(1235,'aa')
select distinct Account,dst from [TB] where dst in(
select dst from [TB] group by dst having Count( dst) >1)
drop table [TB]
Account dst
123 aa
123 bb
1234 aa
1234 bb
1235 aa
create table [TB]([Account] int,[dst] varchar(2))
insert into [TB] values(123,'aa')
insert into [TB] values(123,'aa')
insert into [TB] values(123,'bb')
insert into [TB] values(123,'bb')
insert into [TB] values(1234,'bb')
insert into [TB] values(123,'cc')
insert into [TB] values(1234,'dd')
insert into [TB] values(1234,'aa')
insert into [TB] values(1235,'aa')
select distinct Account,dst from [TB] where dst in(
select dst from [TB] group by dst having Count( dst) >1)
drop table [TB]
Account dst
123 aa
123 bb
1234 aa
1234 bb
1235 aa
#1
数据结构
Account dst
123 AB
12345 AA
123 AA
789 CD
如何找出dst字段相同而account字段不相同的数据
自己先顶起
Account dst
123 AB
12345 AA
123 AA
789 CD
如何找出dst字段相同而account字段不相同的数据
自己先顶起
#2
SEELCT * FROM TB T WHERE EXISTS(SELECT 1 FROM TB WHERE [DST]=T.[DST] AND Account <>T.Account )
#3
试试看
#4
/*
-- Author:SQL77--RICHIE
-- Version:V1.001 Date:2008-05-15--转Flystone
*/
-- Test Data: TB
If object_id('TB') is not null
Drop table TB
Go
Create table TB(Account int,dst varchar(2))
Go
Insert into TB
select 123,'AB' union all
select 12345,'AA' union all
select 123,'AA' union all
select 789,'CD'
Go
--Start
SELECT * FROM TB T WHERE EXISTS(SELECT 1 FROM TB WHERE [DST]=T.[DST] AND Account <>T.Account )
--Result:
/*
(所影响的行数为 4 行)
Account dst
----------- ----
12345 AA
123 AA
(所影响的行数为 2 行)
*/
--End
#5
select * from table where dst in (select dst from table group by dst having count(dst )>1) order by dst
#6
mysql的也可以吗
#7
--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB]([Account] int,[dst] varchar(2))
insert [TB]
select 123,'AB' union all
select 12345,'AA' union all
select 123,'AA' union all
select 789,'CD'
select * from [TB] t where not exists(select 1 from TB where t.Account=Account and t.dst>dst)
/*
Account dst
----------- ----
12345 AA
123 AA
789 CD
(所影响的行数为 3 行)
*/
drop table TB
#8
可能语法不同
#9
不错 好方法 up
#10
试试这个吧,
#11
性能好像不怎么样,我在mysql中执行了好久都出来数据
#12
五万多数据好像就挂了
#13
下面这句好像不行哦
#14
你加索引了没有
#15
这样查出来好像很多垃圾数据啊
#16
那你又不说清楚要什么结果,按你说的就是那个意思呀
#17
declare @t table( Account int , dst varchar(20))
insert into @t values( 123 , 'AB')
insert into @t values( 12345, 'AA')
insert into @t values( 123 , 'AA')
insert into @t values( 12345 , 'AA')
insert into @t values( 789 , 'CD')
select distinct * from @t where dst in(
select dst from @t group by dst having Count( distinct(Account)) >1)
#18
account dst
123 AA
123 AA
123 AA
123 AB
123 AC
12345 AA
123 AA
我要的结果就是:
123 AA
12345 AA
123 AA
123 AA
123 AA
123 AB
123 AC
12345 AA
123 AA
我要的结果就是:
123 AA
12345 AA
#19
自己把顶起来
#20
17楼的
这样好像数据也是有垃圾数据,在ACCOUNT 和dst两个字段都是有很多重复的
这样好像数据也是有垃圾数据,在ACCOUNT 和dst两个字段都是有很多重复的
#21
你是不是还有其他的关联字段啊
#22
整个表是有很多字段,但是我现在只要这两个字段来区分数据
#23
select distinct account ,dst from @t where dst in(
select dst from @t group by dst having Count( distinct(Account)) >1)
修改一下17楼的试试
#24
#25
学习来了
#26
if object_id('[TB]') is not null drop table [TB]
create table [TB]([Account] int,[dst] varchar(2))
insert into [TB] values(123,'aa')
insert into [TB] values(123,'aa')
insert into [TB] values(123,'bb')
insert into [TB] values(123,'bb')
insert into [TB] values(1234,'bb')
insert into [TB] values(123,'cc')
insert into [TB] values(1234,'dd')
insert into [TB] values(1234,'aa')
insert into [TB] values(1235,'aa')
select distinct Account,dst from [TB] where dst in(
select dst from [TB] group by dst having Count( dst) >1)
drop table [TB]
Account dst
123 aa
123 bb
1234 aa
1234 bb
1235 aa
create table [TB]([Account] int,[dst] varchar(2))
insert into [TB] values(123,'aa')
insert into [TB] values(123,'aa')
insert into [TB] values(123,'bb')
insert into [TB] values(123,'bb')
insert into [TB] values(1234,'bb')
insert into [TB] values(123,'cc')
insert into [TB] values(1234,'dd')
insert into [TB] values(1234,'aa')
insert into [TB] values(1235,'aa')
select distinct Account,dst from [TB] where dst in(
select dst from [TB] group by dst having Count( dst) >1)
drop table [TB]
Account dst
123 aa
123 bb
1234 aa
1234 bb
1235 aa