**Claim:** $\displaystyle \displaystyle \sum_{\pi\in S_n}q^{\text{inv}(\pi)}=\prod_{k=1}^{n}\sum_{r=0}^ {k-1}q^r$ for $\displaystyle n\geqslant 2$.

**Proof:** We proceed by induction. For $\displaystyle n=2$ this is clear since $\displaystyle S_2=\left\{\text{id}_{[2]},(1,2)\}$ and so

$\displaystyle \displaystyle \sum_{\pi\in S_2}q^{\text{inv}(\pi)}=q^{\text{inv}(\text{id}_{[2]})}+q^{\text{inv}((1,2))}=q^0+q^1=1+q$

as claimed. Assume now that this is true for $\displaystyle n$ and notice that $\displaystyle S_{n+1}$ is partitioned into two blocks call the blocks $\displaystyle B_1$ and $\displaystyle B_2$. Namely, those which fix $\displaystyle n+1$ and those that don't. Identify now each $\displaystyle \pi\in S_{n+1}$ with it's associated $\displaystyle n+1$-tuple. Then, $\displaystyle S_{n+1}$ is partitioned into the two blocks of the form $\displaystyle (\ast,\cdots,\ast,n+1)$ and $\displaystyle (\ast,\cdots,n+1,\cdots,\ast)$. Note that if $\displaystyle \pi$ is of the second form with $\displaystyle \pi=(\underbrace{\ast,\cdots,\ast}_{\ell},n+1,\cdo ts,\ast)$ and if $\displaystyle \sigma$ is the element of $\displaystyle S_n$ which results from removing that $\displaystyle \ell+1^{\text{th}}$ slot (the one containing $\displaystyle n+1$) then $\displaystyle \text{inv}(\pi)=\text{inv}(\sigma)+\ell$. Thus, it's clear from this that

$\displaystyle \displaystyle \sum_{\pi\in B_2}q^{\text{inv}(\pi)}=\sum_{\ell=1}^{n}q^\ell\su m_{\pi\in S_n}q^{\text{inv}(\pi)}$

Noticing then that for each $\displaystyle \pi\in B_1$ we have that $\displaystyle \pi$ is just a permutation of $\displaystyle [n]$ with the extra condition that $\displaystyle n+1$ always maps to $\displaystyle n+1$ (and in particular it adds not inversions) we can see that

$\displaystyle \displaystyle \sum_{\pi\in B_1}q^{\text{inv}(\pi)}=\sum_{\pi\in S_n}q^{\text{inv}(\pi)}$

Thus,

$\displaystyle \displaystyle \begin{aligned}\sum_{\pi\in S_{n+1}}q^{\text{inv}(\pi)} &= \sum_{\pi\in B_1}q^{\text{inv}(\pi)}+\sum_{\pi\in B_2}q^{\text{inv}(\pi)}\\ &=\sum_{\pi\in S_n}q^{\text{inv}(\pi)}+\sum_{\ell=1}^{n}q^{\ell}\ sum_{\pi\in S_n}q^{\text{inv}(\pi)}\\ &= \sum_{\pi\in S_n}q^{\text{inv}(\pi)}\left(1+q+\cdots+q^n)\\ &= \prod_{k=1}^{n}\sum_{r=0}^{k-1}q^r\sum_{r=0}^{n}q^r\\ &= \prod_{k=1}^{n+1}\sum_{r=0}^{k-1}q^r\end{aligned}$

and the induction is complete.