Skip to content
Advertisement

SQL: Optimize query with multiple CASE statements

I have a query with many CASE statements that runs for a very long time due to the number of rows. In my research I have not found a solution yet. Is there a way to write the CASE statements more efficiently and with better performance?

database: Oracle

table_a
table
table_y
are all the same table where I SELECT from.

example data

contract_number product_description product damagenumber date internalname payment
1 Product T-Shirt product_name 111 20210101 Web 30.20
2 Product T-Shirt product_name 222 20210202 Web 19.38
3 Product Hoodie product_name2 333 20210215 Store 20.49
3 Product Hoodie product_name2 334 20210302 Store 15.99
5 Product Hoodie product_name2 123 20210120 Telephone 99.99

The above is a simplified example. I have a lot of WHEN conditions in my query.

Thanks in advance

Advertisement

Answer

maybe this help

Maybe this query have some errors (I can’t test) but you should try this way

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