0
\$\begingroup\$

I'm running the following query on my database:

SELECT 
    DATE(timestamp) as timestamp,
    AVG(AVG(row_one)) OVER (ORDER BY DATE(timestamp) ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) as row_one,
    AVG(AVG(row_two)) OVER (ORDER BY DATE(timestamp) ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) as row_two,
    AVG(AVG(row_three)) OVER (ORDER BY DATE(timestamp) ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) as row_three
FROM entries
WHERE uid = 'uid' AND
timestamp >= '2019-01-01' AND timestamp < '2019-01-30'
GROUP BY DATE(timestamp)
ORDER BY DATE(timestamp) DESC

Now, here I'm limiting the selected number of columns, my actually query that I'm running pulls in about 10 columns. This can get quite untidy, is there a way I can run the same window function on all selected rows or just make it cleaner?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.