If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Can we speed this up?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-27-04, 04:32
Napivo Napivo is offline
Registered User
 
Join Date: Jul 2004
Posts: 3
Can we speed this up?

I wonder if there is any way to accelerate a query like this. This one is taking about 5 secs on my access database

Code:
(SELECT '1', Count(tblBase_Logs.Date) AS Cnt From tblBase_Logs 
WHERE (((tblBase_Logs.Date) between #07/04/2004# 
And #07/05/2004#)And ([Spend]> 15)And ([Web] = 'Web2')))
Union (SELECT '2', Count(tblBase_Logs.Date) AS Cnt From tblBase_Logs 
WHERE (((tblBase_Logs.Date) between #07/04/2004# 
And #07/05/2004#)And ([Spend] between 10 and 15)And ([Web] = 'Web2')))
Union (SELECT '3', Count(tblBase_Logs.Date) AS Cnt From tblBase_Logs 
WHERE (((tblBase_Logs.Date) between #07/04/2004# 
And #07/05/2004#)And ([Spend] between 5 and 10)And ([Web] = 'Web2')))
Union (SELECT '4', Count(tblBase_Logs.Date) AS Cnt From tblBase_Logs 
WHERE (((tblBase_Logs.Date) between #07/04/2004# 
And #07/05/2004#)And ([Spend] <= 5)And ([Web] = 'Web2')))
Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 07-27-04, 07:46
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Does Access suport CASE?
Code:
SELECT CASE WHEN Spend > 15 THEN '1'
            WHEN Spend between 10 and 15 THEN '2'
            WHEN Spend between 5 and 10 THEN '3'
            WHEN Spend <= 5 THEN '4'
       END,
       Count(tblBase_Logs.Date) AS Cnt 
From   tblBase_Logs 
WHERE  tblBase_Logs.Date between #07/04/2004# And #07/05/2004#
And    Web = 'Web2'
GROUP BY CASE WHEN Spend > 15 THEN '1'
            WHEN Spend between 10 and 15 THEN '2'
            WHEN Spend between 5 and 10 THEN '3'
            WHEN Spend <= 5 THEN '4'
       END
BTW, note that you have a Spend value of 10 falling into both '2' and '3' groups.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews

Last edited by andrewst; 07-27-04 at 07:49.
Reply With Quote
  #3 (permalink)  
Old 07-27-04, 07:59
Napivo Napivo is offline
Registered User
 
Join Date: Jul 2004
Posts: 3
Thumbs up

I just tried and it doesn’t Sorry for your nice work.

I have been messing around with my indexes and managed to get the query below one sec of execution. That’s more acceptable than the 5 secs I had before.

I loose a bit of speed while entering data in the database (2 min over 200 000 records) but that’s ok.

Thank you for your time.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On