0

次のクエリでは、すべての isrc の持続時間が 300000 ミリ秒未満で、トラック数が 11 で、所有地域が 31,201,41,125 にない upcs を取得しようとしています)。

select  r.UPC ,r.Id, res.ISRC , res.Duration ,COUNT( res.ISRC) from Release r 
inner join ReleaseResource rr on rr.ReleaseId=r.Id
inner join Resource res on res.Id=rr.ResourceId
inner join ReleaseTerritory rt on rt.ReleaseId=r.id
where   not r.OwningTerritoryId in (31,201,41,125) and res.Duration<5*60000 and  r.TrackCount=11 and rt.IsDeleted=0
group by r.UPC ,r.Id, res.ISRC , res.Duration
having COUNT( distinct rt.TerritoryId)=10  
order by r.upc

クエリが 300000 ミリ秒未満の isrc のみを表示する isrc を除いて、得られる結果は良好ですが、upc の内部を見ると、300000 ミリ秒を超える持続時間を持つ他の isrc があることがわかります。すべての isrcs が 300000 ミリ秒未満の upcs のみを取得するには、何を変更する必要がありますか? ありがとう

4

1 に答える 1

1

GROUPINGの前に「300000ミリ秒未満の期間」を除外しているためです.. WHEREからフィルターを削除し、HAVINGでこれを試してください

select  r.UPC ,r.Id, res.ISRC , res.Duration ,COUNT( res.ISRC) from Release r 
inner join ReleaseResource rr on rr.ReleaseId=r.Id
inner join Resource res on res.Id=rr.ResourceId
inner join ReleaseTerritory rt on rt.ReleaseId=r.id
where   not r.OwningTerritoryId in (31,201,41,125) and  r.TrackCount=11 and rt.IsDeleted=0
group by r.UPC ,r.Id, res.ISRC , res.Duration
having COUNT( distinct rt.TerritoryId)=10  AND MAX(res.Duration)<5*60000
order by r.upc
于 2013-06-14T14:48:16.147 に答える