Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selection problem
Message
De
29/06/2011 09:11:47
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01516648
Message ID:
01516674
Vues:
37
>>>I believe you need to reverse the condition, e.g.
>>>
>>>;with cte as (select T.*, row_number() over (order by NewID()) as RandomRow 
>>>from Test T where not exists (select 1 from Test T2 where T.FamilyID = T2.PartnerID))
>>>
>>>select * from cte where RandomRow <=4
>>>
>>>The above is from the top of my head - and may be a bit slow.
>>
>>
>>With such cross data (if you see Nicholas has the same IDs in BOTH fields) you wouldn't get any rows.
>
>Good point.
>
>I will need to think about it more - it's not very trivial.

Well I've ended up with this
select select top (@RecCount)  m.membership_no,m.member_ref
into tempdb.dbo.step1
from member m
join individual i
on m.individual_ref = i.individual_ref
left join individual i2
on i2.family_ref = i.individual_ref
where  ((i.individual_ref < i2.individual_ref ) or i2.individual_ref is null) -- suppress partner duplicates
order by newid()
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform