A basic nilsequence is a sequence of the form ψ(n)=f(Tnx), where x is a point of a compact nilmanifold X, T is a translation on X, and f∈C(X); a nilsequence is a uniform limit of basic nilsequences. Let X=G/Γ be a compact nilmanifold, Y be a subnilmanifold of X, g(n) be a polynomial sequence in G, and f∈C(X); we show that the sequence ∫ g(n)Yf, n∈ℤ, is the sum of a basic nilsequence and a sequence that converges to zero in uniform density. This implies that, given an ergodic invertible measure-preserving system (W,ℬ,μ,T), with μ(W)<∞, polynomials p1,…,pk∈ℤ[n], and sets A1,…,Ak∈ℬ, the sequence μ(Tp1(n)A1∩⋯∩Tpk(n)Ak) is the sum of a nilsequence and a sequence that converges to zero in uniform density. We also obtain a version of this result for the case where pi are polynomials in several variables.