E
E
exel1k2015-11-02 20:42:14
MySQL
exel1k, 2015-11-02 20:42:14

How to make query in sql using subquery?

I ask for help in solving the SQL problem:
Display a list of facilities whose electricity consumption in the summer months of 2012 is lower than the average electricity consumption for the facilities as a whole for 2012 (name of the facility, electricity consumption, month)
35f9e6ec970f4dfd8a9985b9d66f03cd.png
started a little, but I can't finish(
SELECT ob.name_o, potr.vel, res.kod_rs, potr.mes
FROM ob,potr, res
WHERE
potr.kod_o=ob.kod_o
and
res.kod_rs=potr.kod_rs
and
rs.kod_rs=5
and

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nozzy, 2015-11-02
@exel1k

Didn't check how proof of concept

SELECT 
p.kod_o,
p.kod_rs,
p.mes,
p.vel
FROM potr p
INNER JOIN 
(
SELECT 
kod_o "kod",
AVG(vel) "vel"
FROM potr
WHERE god_potr = '2012'
GROUP BY kod_o
) t on t.kod = p.kod_o 
and t.vel > p.vel
WHERE 1=1
AND p.god_potr = '2012'
AND p.mes IN (6,7,8)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question