如何筛选

问题描述:

我有列如何筛选

SponsorID AccountID CountryID 
123  456  236 
123  789  236 
123  654  40 
123  897  236 
123  978  40 
123  564  40 
    '   '   ' 
    '   '   ' 
    '   '   ' 

我想写一个sql查询查找表上数记录(具体列值)sponsorID的谁拥有比countryID = 40多个accountIDs计数10 [count(CountryID = 40)> 10]

+1

请问你可以发布你的代码到目前为止你试过了吗? – user1140237

+1

你是否在同一时间使用'sql'的所有3 _versions_? – BNN

+0

我认为你应该尝试类似于'SELECT赞助商来自表名 WHERE CountryID = 40 GROUP BY主办单位 HAVING COUNT(CountryID)> 10' – pedram

Create 2 table (`TEMP` or `CTE`). 
1)SponsorID , count(AccountID)>0 
2)SponsorID ,count(CountryID)>10 where CountryID=40 
now join them. 
+0

@ user1140237。这里是我现在的地方。 SELECT TOP 1 SponsorID FROM( SELECT et.sponsorID,COUNT(et.AccountID)AS downlinecount FROM commissions。[calcs]。[vwEnrollerTreePermutated] et INNER JOIN Commissions。[RFO]。[synvw_GetAccount_Reporting] gar ON et.AccountID = gar 。帐户ID WHERE PeriodID =(SELECT MAX(PeriodID)FROM commissions.Reference.Periods WHERE ClosedDate IS NOT null) GROUP BY et.SponsorID HAVING COUNT(et.AccountID)在1350和1500之间(COUNT)(gar.countryID)> 2)a ORDER BY NEWID()。无法弄清楚如何获得具有CountryID = 40的AccountID的数量。 –