A
A
atatundra2020-09-15 08:18:46
PostgreSQL
atatundra, 2020-09-15 08:18:46

What is the best way to write SQL query?

The feeling that this query can be written more concisely does not leave the feeling, but it does not reach how!

select  'Панель 1 ' as "панель",
        (select sum(no_light)/3600.0 from sector1  where button=1 AS "кнопка 1",
        (select sum(no_light)/3600.0 from sector1  where button=2 AS "кнопка 2",
        (select sum(no_light)/3600.0 from sector1  where button=3 AS "кнопка 3",
        (select sum(no_light)/3600.0 from sector1  where button=4 AS "кнопка 4",
        (select sum(no_light)/3600.0 from sector1  where button=5 AS "кнопка 5",
        (select sum(no_light)/3600.0 from sector1  where button=6 AS "кнопка 6",
        (select sum(no_light)/3600.0 from sector1  where button=7 AS "кнопка 7",
        (select sum(no_light)/3600.0 from sector1  where button=8 AS "кнопка 8",
        (select sum(no_light)/3600.0 from sector1  where button=9 AS "кнопка 9",
        (select sum(no_light)/3600.0 from sector1  where button=10 AS "кнопка 0",
        (select sum(no_light)/3600.0 from sector1  where button=0 AS "не выбрано";

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Matveev, 2020-09-19
@ematveev

can use IN() ? then inside the brackets you can list an array of values ​​​​and compare in WHERE with one field

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question