For example I have the following list of calls:
- Call#1 - duration 30 min
- Call#2 - duration 43 min
- Call#3 - duration 26 min
- Call#4 - duration 35 min
- Call#5 - duration 39 min
1) I need the SQL query retrieving the average duration of first 80% of calls.
Calls that fall into first 80% (according to call duration) are calls #3,#1,#4,#5. For these calls the average duration should be calculated ((26+30+35+39)/4=32,5). Calls above 80% (here call #2) should be ignored.
2) Also I need the vice versa query - what percentage of first calls will have the average call duration of 30 mins?
3) Hot to fetch the duration of 80%-th record (ordered according to call duration). E.g. if there's 500 records, what's the duration of 400th record?
How this SQL queries should look like (Oracle)?