Example Data:
╔════╦════════════╦════════════╦═══════╦═══════════╦════════╗ ║ ID ║ START ║ STOP ║ USER ║ FILE ║ SIZE ║ ╠════╬════════════╬════════════╬═══════╬═══════════╬════════╣ ║ 1 ║ 1330133409 ║ 1330133410 ║ user1 ║ file1.zip ║ 300000 ║ ║ 2 ║ 1330133409 ║ 1330133410 ║ user1 ║ file2.zip ║ 300500 ║ ║ 3 ║ 1330133409 ║ 1330133410 ║ user2 ║ file1.zip ║ 300000 ║ ║ 4 ║ 1330133409 ║ 1330133410 ║ user2 ║ file2.zip ║ 300500 ║ ║ 5 ║ 1330133409 ║ 1330133410 ║ user1 ║ file3.zip ║ 500000 ║ ║ 6 ║ 1330133409 ║ 1330133310 ║ user6 ║ file3.zip ║ 500000 ║ ╚════╩════════════╩════════════╩═══════╩═══════════╩════════╝
I need to create a MySQL query that computes PER_USER_AVERAGE_BANDWIDTH where PER_USER_AVERAGE_BANDWIDTH = SUM(SIZE) / (STOP - START), and then order by PER_USER_AVERAGE_BANDWIDTH to produce results like this:
╔═══════╦════════════════════════════╗ ║ USER ║ PER_USER_AVERAGE_BANDWIDTH ║ ╠═══════╬════════════════════════════╣ ║ user3 ║ 110.37 ║ ║ user1 ║ 100.25 ║ ║ user2 ║ 75.70 ║ ╚═══════╩════════════════════════════╝
Clear as mud ;) Anyone?
user1,user2, anduser6- where doesuser3in the result set come from? Also, how do youSUM(SIZE)(multiple rows) but only use one row in(STOP - START)? There are three rows foruser1- which would you expect to be used for that part of the calculation? (Yes, I realize in this caseSTOPandSTARTare the same values for all three rows, but the database doesn't know that when it's parsing the SQL.) - Ken White