2

The question that I would like to answer is: Present the average number of students who travel in a particular route per week.

What I have tried:

SELECT SUM(NO_OF_SEATS) "WEEKLY AVG"
FROM RESER;

This code shows me the average number of students only, but I want the average per week and I don't know how to get that.

I tried this but it's wrong:

SELECT SUM(NO_OF_SEATS) "WEEKLY AVG"
TO_CHAR(TRUNC(MIN(TRAVEL_DATE), 'WW') + 1, 'FORMAT')
FROM RESER;
Tom H
47.5k15 gold badges90 silver badges133 bronze badges
asked Apr 8, 2016 at 20:14
2
  • What error or issue are you getting with your query you tried? Commented Apr 8, 2016 at 20:24
  • Some Very odd data if SUM() = AVG()... Commented Apr 8, 2016 at 20:27

1 Answer 1

2

Try this:

SELECT AVG(NO_OF_SEATS) "WEEKLY AVERAGE", TRUNC(TRAVEL_DATE,'IW')
FROM RESER
GROUP BY TRUNC(TRAVEL_DATE,'IW');

'WW' = Assumes the first day starts on January 1st and will go in 7 day increments. Weeks will potentially start on a day that is not Monday.
'IW' = Will always start the week on a Monday.

answered Apr 8, 2016 at 20:24
Sign up to request clarification or add additional context in comments.

2 Comments

@user5520587 - if MikeS's answer worked for you, you may want to mark it as "Correct Answer" - otherwise the question will continue to show among the unanswered questions. Thank you!
I wouldn't mind having another correct answer under my belt as well. Thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.