Hi guys,
Trying to do a query to produce a count by dealer code of when certain things are true about a quote raised by that dealer.
the main tables i am using are the Quote table and the QuoteItem table (quote has details on when the quote was raised and by who, QuoteItem contains details of the items on that quote)
There are 3 counts i need to do - one for 'standard' items on the quote, one for 'Miscelanious' items, and one for custom jobs.
The way to tell these 3 types apart are a column called Type in the QuoteItem table which can be one of the following values.....
...the same quote number can have many of these against it though.
- Standard jobs will always have a type of 'JOB' attached to it
- Custom jobs will always have a type of 'CJOB' attached to it
- The 'MISC' items jobs - can have any of the types listed above but will not have 'CJOB' or 'JOB' attached to it.
I have tried the following for the 'MISC' items part....
but it took nearly 14 minutes to complete!!
Is there a more efficient way to do this?
Cheers..
Trying to do a query to produce a count by dealer code of when certain things are true about a quote raised by that dealer.
the main tables i am using are the Quote table and the QuoteItem table (quote has details on when the quote was raised and by who, QuoteItem contains details of the items on that quote)
There are 3 counts i need to do - one for 'standard' items on the quote, one for 'Miscelanious' items, and one for custom jobs.
The way to tell these 3 types apart are a column called Type in the QuoteItem table which can be one of the following values.....
Code:
CJOB
DEAL
JOB
LABR
LITM
MITM
PART
PITM
...the same quote number can have many of these against it though.
- Standard jobs will always have a type of 'JOB' attached to it
- Custom jobs will always have a type of 'CJOB' attached to it
- The 'MISC' items jobs - can have any of the types listed above but will not have 'CJOB' or 'JOB' attached to it.
I have tried the following for the 'MISC' items part....
Code:
select d.Code,count(Id_Quote)
from Quote q
inner join Dealer d on d.Id_Dealer = q.Id_Dealer and d.Code_Market = 'ES'
where Id_Quote in (select Id_Quote from QuoteItem where Type in ('PART','LITM','LABR','MITM','DEAL','PITM'))
and Id_Quote not in (select Id_Quote from QuoteItem where Type = 'JOB')
group by d.Code
but it took nearly 14 minutes to complete!!
Is there a more efficient way to do this?
Cheers..