Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've been having trouble understanding with Performance Tuning previous queries. Underneath is the query that I am trying to improve by adding an index.

Thank you for your help.

Query:
SQL
select model, descr, mpg,
(
select count(*) from car_details where mpg is not null) as "Number of Cars"
from car_names, car_details
where car_details.id = car_names.id and mpg is null
for (reg_name) in ('NE', 'NW', 'SE', 'SW')
);



SQL Script File:

https://docs.google.com/document/d/1vClWrxZnU3AKhQzeWwqbMtf5du-3EcfHTuLdbgGvxU4/edit?usp=sharing

What I have tried:

I've tried making simple insert statements but it looks like it made no changes in performance.
Posted
Updated 2-May-19 22:00pm
v2

1 solution

Get rid of subqueries. Instead use a CTE to create a table with totals and ids to match against.

The rest seems reasonable.
 
Share this answer
 
Comments
Maciej Los 3-May-19 4:00am    
5ed!
Christian Graus 3-May-19 4:05am    
Thanks. I have an article on this site on CTEs if you need pointers

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900