P
P
Prosghvatn2017-01-23 23:03:12
MySQL
Prosghvatn, 2017-01-23 23:03:12

How to do arithmetic mean in SQL query?

How to create an arithmetic mean of `stud`.`E1`, `stud`.`E2`, `stud`.`E3` both in rows, as it is now, and in columns to get one number?
SELECT `stud`.`Name`
FROM `stud`
WHERE EXISTS(SELECT NumS
FROM `rob_gurt`
WHERE
((`stud`.`NumS` = `rob_gurt`.`NumS`) AND (`rob_gurt`.`NumG` = 1) AND ( `stud`.`E1`<=
(`stud`.`E1` + `stud`.`E2` + `stud`.`E3`)/3) )
)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Prosghvatn, 2017-01-24
@Prosghvatn

SELECT `stud`.`Name`
FROM `stud`
INNER JOIN
(SELECT AVG(`stud`.`E1` + `stud`.`E2` + `stud`.`E3`) / 3 AS average
FROM `stud`
INNER JOIN `rob_gurt`
ON `rob_gurt`.`NumS` = `stud`.`NumS`
INNER JOIN `gurt`
ON `gurt`.`NumG` = `rob_gurt`.`NumG`
WHERE `gurt`.`NameG` = "Music") AS q
ON `stud`.`E1` <= q.average

V
Vincent1, 2017-01-23
@Vincent1

I see it's hard for you to have a session. AVG() to help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question