Skip to content
Advertisement

Slow query with join – works fast as individual queries

I have a sales table with a sales column TCV, customerKey column which holds customerKey stored in customer table. Each row has an order_date and there are other columns irrelevant to this query.

I have to find sales for current period and another period grouped by customers for comparison. So I have this below query.

I have this query and it runs very slowly, takes about 30 secs, but if I run the query without the join the result comes back in a second.

What could be the problem, is it structured wrong?

Advertisement

Answer

Rewrite it without join, it will perform better:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement