PC Review


Reply
Thread Tools Rate Thread

Complex Query in Access

 
 
Huyeote
Guest
Posts: n/a
 
      4th Aug 2003
Hi, there, I have a Access table which contains hundreds of thousands of
call logs. The data fields useful in this case is phone number (area code +
phone no) and duration. And I have another table which records all billable
area codes (prefix). I need to summarise total of minutes called to every
single area code from the call details table. Instead of query one area code
every time in a simple query, can I query minutes to all prefix ( I have
more than 500 prefix) in just one go? Any help will be appreciated.

Thanks.

Regards,

Huyeote




 
Reply With Quote
 
 
 
 
Arvi Laanemets
Guest
Posts: n/a
 
      4th Aug 2003
Hi

On fly:

Without using area codes table (area codes must be all fixed length, p.e. 3
characters, and you get only areas with calls):
Select Left(PhoneNumber,3) As Area, SUM(Duration) As Duration From
CallTable Group By Left(PhoneNumber,3) Order By 1

Using area codes table:
Select b.Area, SUM(a.Duration) From CallTable a, AreaTable b Where
Left(a.PhoneNumber,Len(b.Area))=b.Area Group By b.Area Order By 1


Arvi Laanemets



"Huyeote" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi, there, I have a Access table which contains hundreds of thousands of
> call logs. The data fields useful in this case is phone number (area code

+
> phone no) and duration. And I have another table which records all

billable
> area codes (prefix). I need to summarise total of minutes called to every
> single area code from the call details table. Instead of query one area

code
> every time in a simple query, can I query minutes to all prefix ( I have
> more than 500 prefix) in just one go? Any help will be appreciated.
>
> Thanks.
>
> Regards,
>
> Huyeote
>
>
>
>



 
Reply With Quote
 
John Vinson
Guest
Posts: n/a
 
      4th Aug 2003
On Mon, 4 Aug 2003 14:52:19 +1000, "Huyeote" <(E-Mail Removed)>
wrote:

>Hi, there, I have a Access table which contains hundreds of thousands of
>call logs. The data fields useful in this case is phone number (area code +
>phone no) and duration. And I have another table which records all billable
>area codes (prefix). I need to summarise total of minutes called to every
>single area code from the call details table. Instead of query one area code
>every time in a simple query, can I query minutes to all prefix ( I have
>more than 500 prefix) in just one go? Any help will be appreciated.


Yes, you can, but since apparently you have the area code embedded in
the phone number instead of as a separate (indexed) field, it will be
very slow and inefficient.

Two ways to try, making guesses at your fieldnames which you'll need
to correct:

1. SELECT BillableCodes.AreaCode, Sum(Calls.Calltime) AS SumOfTime
FROM Calls, BillableCodes
WHERE Calls.Phone LIKE BillableCodes.Code & "*"
GROUP BY BillableCodes.AreaCode;

2. a Non Equi Join:

SELECT BillableCodes.AreaCode, Sum(Calls.Calltime) AS SumOfTime
FROM Calls INNER JOIN BillableCodes
ON Calls.Phone LIKE BillableCodes.Code & "*"
GROUP BY BillableCodes.AreaCode;


John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public

 
Reply With Quote
 
Huyeote
Guest
Posts: n/a
 
      4th Aug 2003
Thanks for the query, it does work. But the grand total minutes of the equey
is larger than what I got if I only query durations. The problem is due to
overlap of some prefix like 21 & 217. Minutes called to 217 is also included
in the minutes called to 21. How can I solve this problem?

Hueyote


"Arvi Laanemets" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> On fly:
>
> Without using area codes table (area codes must be all fixed length, p.e.

3
> characters, and you get only areas with calls):
> Select Left(PhoneNumber,3) As Area, SUM(Duration) As Duration From
> CallTable Group By Left(PhoneNumber,3) Order By 1
>
> Using area codes table:
> Select b.Area, SUM(a.Duration) From CallTable a, AreaTable b Where
> Left(a.PhoneNumber,Len(b.Area))=b.Area Group By b.Area Order By 1
>
>
> Arvi Laanemets
>
>
>
> "Huyeote" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi, there, I have a Access table which contains hundreds of thousands of
> > call logs. The data fields useful in this case is phone number (area

code
> +
> > phone no) and duration. And I have another table which records all

> billable
> > area codes (prefix). I need to summarise total of minutes called to

every
> > single area code from the call details table. Instead of query one area

> code
> > every time in a simple query, can I query minutes to all prefix ( I have
> > more than 500 prefix) in just one go? Any help will be appreciated.
> >
> > Thanks.
> >
> > Regards,
> >
> > Huyeote
> >
> >
> >
> >

>
>



 
Reply With Quote
 
Huyeote
Guest
Posts: n/a
 
      4th Aug 2003
Thanks for the query, it's simpler than I thought. But the grand total
minutes of the equey is larger than what I got if I only query durations.
The problem is due to overlap of some prefix like 21 & 217. Minutes called
to 217 is also included in the minutes called to 21. How can I solve this
problem?



"John Vinson" <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in message
news:(E-Mail Removed)...
> On Mon, 4 Aug 2003 14:52:19 +1000, "Huyeote" <(E-Mail Removed)>
> wrote:
>
> >Hi, there, I have a Access table which contains hundreds of thousands of
> >call logs. The data fields useful in this case is phone number (area code

+
> >phone no) and duration. And I have another table which records all

billable
> >area codes (prefix). I need to summarise total of minutes called to every
> >single area code from the call details table. Instead of query one area

code
> >every time in a simple query, can I query minutes to all prefix ( I have
> >more than 500 prefix) in just one go? Any help will be appreciated.

>
> Yes, you can, but since apparently you have the area code embedded in
> the phone number instead of as a separate (indexed) field, it will be
> very slow and inefficient.
>
> Two ways to try, making guesses at your fieldnames which you'll need
> to correct:
>
> 1. SELECT BillableCodes.AreaCode, Sum(Calls.Calltime) AS SumOfTime
> FROM Calls, BillableCodes
> WHERE Calls.Phone LIKE BillableCodes.Code & "*"
> GROUP BY BillableCodes.AreaCode;
>
> 2. a Non Equi Join:
>
> SELECT BillableCodes.AreaCode, Sum(Calls.Calltime) AS SumOfTime
> FROM Calls INNER JOIN BillableCodes
> ON Calls.Phone LIKE BillableCodes.Code & "*"
> GROUP BY BillableCodes.AreaCode;
>
>
> John W. Vinson[MVP]
> Come for live chats every Tuesday and Thursday
> http://go.compuserve.com/msdevapps?loc=us&access=public
>



 
Reply With Quote
 
Arvi Laanemets
Guest
Posts: n/a
 
      4th Aug 2003
Hi


I'm afraid you have a serious problem there due your earlier database
design. As I understand, area codes can be different length. When phone
numbers also can have different length, the only option you have left, is
manually sort them between areas. When ALL phone numbers (without area code)
are same length, then you can try something like:
Select b.Area, SUM(a.Duration) From CallTable a, AreaTable b Where
Left(a.PhoneNumber,Len(a.PhoneNumber)-LengthOfPhoneNumber)=b.Area Group By
b.Area Order By 1


Arvi Laanemets


"Arvi Laanemets" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> On fly:
>
> Without using area codes table (area codes must be all fixed length, p.e.

3
> characters, and you get only areas with calls):
> Select Left(PhoneNumber,3) As Area, SUM(Duration) As Duration From
> CallTable Group By Left(PhoneNumber,3) Order By 1
>
> Using area codes table:
> Select b.Area, SUM(a.Duration) From CallTable a, AreaTable b Where
> Left(a.PhoneNumber,Len(b.Area))=b.Area Group By b.Area Order By 1
>
>
> Arvi Laanemets
>
>
>
> "Huyeote" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi, there, I have a Access table which contains hundreds of thousands of
> > call logs. The data fields useful in this case is phone number (area

code
> +
> > phone no) and duration. And I have another table which records all

> billable
> > area codes (prefix). I need to summarise total of minutes called to

every
> > single area code from the call details table. Instead of query one area

> code
> > every time in a simple query, can I query minutes to all prefix ( I have
> > more than 500 prefix) in just one go? Any help will be appreciated.
> >
> > Thanks.
> >
> > Regards,
> >
> > Huyeote
> >
> >
> >
> >

>
>



 
Reply With Quote
 
John Vinson
Guest
Posts: n/a
 
      4th Aug 2003
On Mon, 4 Aug 2003 16:29:48 +1000, "Huyeote" <(E-Mail Removed)>
wrote:

>Thanks for the query, it's simpler than I thought. But the grand total
>minutes of the equey is larger than what I got if I only query durations.
>The problem is due to overlap of some prefix like 21 & 217. Minutes called
>to 217 is also included in the minutes called to 21. How can I solve this
>problem?


Hrm. I thought that Area Codes were all three digits. What is a 21
prefix!?

This will be MUCH MUCH more difficult, since if you have a Phone field
containing

2174444444

there is no obvious way to tell whether that's a 21 or a 217 code.


John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public
 
Reply With Quote
 
Huyeote
Guest
Posts: n/a
 
      5th Aug 2003
Sorry, I should tell you the phone number string has country code as well as
area code. I just made an example using dummy figure like 21 & 217. To be
more specific, we can use 66 which is the country code for Thailand, and 662
(66 + area code 2) for Bangkok. Now I know there is no simple way to do it
in SQL. Thanks any way.

Huyeote

"John Vinson" <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in message
news:(E-Mail Removed)...
> On Mon, 4 Aug 2003 16:29:48 +1000, "Huyeote" <(E-Mail Removed)>
> wrote:
>
> >Thanks for the query, it's simpler than I thought. But the grand total
> >minutes of the equey is larger than what I got if I only query durations.
> >The problem is due to overlap of some prefix like 21 & 217. Minutes

called
> >to 217 is also included in the minutes called to 21. How can I solve this
> >problem?

>
> Hrm. I thought that Area Codes were all three digits. What is a 21
> prefix!?
>
> This will be MUCH MUCH more difficult, since if you have a Phone field
> containing
>
> 2174444444
>
> there is no obvious way to tell whether that's a 21 or a 217 code.
>
>
> John W. Vinson[MVP]
> Come for live chats every Tuesday and Thursday
> http://go.compuserve.com/msdevapps?loc=us&access=public



 
Reply With Quote
 
John Vinson
Guest
Posts: n/a
 
      5th Aug 2003
On Tue, 5 Aug 2003 12:03:55 +1000, "Huyeote" <(E-Mail Removed)>
wrote:

>Sorry, I should tell you the phone number string has country code as well as
>area code. I just made an example using dummy figure like 21 & 217. To be
>more specific, we can use 66 which is the country code for Thailand, and 662
>(66 + area code 2) for Bangkok. Now I know there is no simple way to do it
>in SQL.


If you don't have the country codes and the area codes distinguished
in SOME way, then I cannot imagine any way to do it in SQL *or any
other way*. For instance, is 6032564113 a number in the US in area
code 603, or Malaysia 60+Kuala Lumpur 3? How would you tell?


John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query is too complex for Access 2007 ? Will Microsoft Access 2 27th Jan 2009 07:12 PM
Query is too complex for Access 2007 ? Will Microsoft Access Queries 2 27th Jan 2009 03:27 PM
$ Complex Access Query david.barbetta@gmail.com Microsoft Access Queries 4 13th May 2008 11:55 PM
Query too complex? Access 2003 =?Utf-8?B?UGF1bCAoRVNJKQ==?= Microsoft Access Queries 8 26th Jan 2006 01:01 AM
Fix Query too Complex error in Access =?Utf-8?B?RG91Zw==?= Microsoft Access Queries 1 20th Jun 2005 05:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:17 PM.