Hello... I have the following data:
I need to know each instrumentid, saddition, block where multiple lotlengths exist exit per each instrumentid, saddition, block.
In this example:
'aa11' has 2 separate lotlengths for 'aa11', 'sp1', '5'
'aa12' has 2 separate lotlengths for 'aa12', 'sp6', '10'
I'm hoping for a query that can show this. I just can't get my grouping right.
I tried:
But this doesn't work.
Thanks!
Code:
create table #temp (instrumentID varchar(25), saddition varchar(50), block varchar(10), Lot varchar(10), LotLength int)
insert into #temp values ('aa11', 'SP1', '5', '9', 1)
insert into #temp values ('aa11', 'SP1', '5', '10', 2)
insert into #temp values ('aa12', 'SP5', '9', '10', 2)
insert into #temp values ('aa12', 'SP5', '9', '11', 2)
insert into #temp values ('aa12', 'SP5', '9', '12', 2)
insert into #temp values ('aa12', 'SP6', '10', '5', 1)
insert into #temp values ('aa12', 'SP6', '10', '10', 2)
insert into #temp values ('aa13', 'SP7', '123', '31', 2)
insert into #temp values ('aa13', 'SP7', '123', '32', 2)
I need to know each instrumentid, saddition, block where multiple lotlengths exist exit per each instrumentid, saddition, block.
In this example:
'aa11' has 2 separate lotlengths for 'aa11', 'sp1', '5'
'aa12' has 2 separate lotlengths for 'aa12', 'sp6', '10'
I'm hoping for a query that can show this. I just can't get my grouping right.
I tried:
Code:
select distinct instrumentid, saddition, block
from #temp
group by instrumentid, saddition, block
having count(block) > 1
But this doesn't work.
Thanks!