I was reading Apostol's book Introduction to Analytic Number Theory, and was trying to use the method introduced in this book to evaluate $\frac{1}{n}\sum_{1\leq m\leq n}\sigma(m),$ where $\sigma(m)$ is the sum of of all positive divisors of $m.$
Using the method in the book, I got \begin{align*} \frac{1}{n}\sum_{1\leq m\leq n}\sigma(m)&=\frac{1}{n}\sum_{1\leq m\leq n}\sum_{d|m}d= \frac{1}{n}\sum_{1\leq m\leq n}\sum_{d|m}\frac{m}{d}\\ &(*)=\frac{1}{n}\sum_{\substack{d,q\\{1\leq dq\leq n}}}q=\frac{1}{n}\sum_{d\leq n}\sum_{q\leq\frac{n}{d}}q=\frac{1}{n}\sum_{d\leq n}\frac{1}{2}[\frac{n}{d}]([\frac{n}{d}]+1)\\ &=\frac{1}{2n}\sum_{d\leq n}(\frac{n}{d}+O(1))(\frac{n}{d}+O(1)) \frac{1}{2n}\sum_{d\leq n}\frac{n^2}{d^2}+O(1+\log n)\\&=\frac{\pi^2}{12}n+O(1+\log n), \quad \text{which is the correct answer.} \end{align*} But at step $(*)$, if I interchange the oder of $q$ and $d$ in the summation, I got something different \begin{align*} \frac{1}{n}\sum_{1\leq m\leq n}\sigma(m)&=\frac{1}{n}\sum_{q\leq n}q\sum_{d\leq{\frac{n}{q}}}1=\frac{1}{n}\sum_{q\leq n}q[\frac{n}{q}]=\frac{1}{n}\sum_{q\leq n}q(\frac{n}{q}+O(1))\\ &=\sum_{q\leq n}1+O(\frac{1}{n}\sum_{q\leq n}q)=[n]+O(n)=n+O(n). \end{align*} The above expression I obtained using the second method is apparently not correct. But given my calculation at each step is correct, where did I go wrong with the second method? Will I essentially obtain the same result as in the first method?
Many thanks for your help in advance.