I
I
Ivan_R22020-09-15 20:59:54
PostgreSQL
Ivan_R2, 2020-09-15 20:59:54

How to make a SQL query on a list of id, instead of the whole table?

Hello!
Can you please tell me how to edit the query so that the calculation is not for the entire table, but for the id list?
Filtering the results is not suitable, because the query takes too long, the database is large enough, there are a lot of records.

The request itself:

SELECT my_table.id AS id, sum(child.qty) AS all_child_qty
FROM my_table
LEFT OUTER JOIN my_table as child
   ON child.my_path LIKE (my_table.my_path || '%')
GROUP BY my_table.id
);

The query produces the following result:
5f61010e7403b859150582.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman, 2020-09-15
@Ivan_R2

...
WHERE my_table.`id` IN (<ids_coma_separated_list>)
GROUP BY ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question