Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Query Help

Author  Topic 

spanki
Starting Member

8 Posts

Posted - 2002-05-19 : 03:01:06
I have a table with the colomn orig! orig is the origination of a phone call.

I have another table with the colomn extn! which means extension number.

the last 4 numbers of the orig phone number is the extension.

how would i go about listing the amount of calls by extension number!?!?


Nazim
A custom title

1408 Posts

Posted - 2002-05-19 : 03:08:40

select right(phoneno,4) as Extension,count(*) as CountofCalls from phonebook p
inner join extensiontable e
on p.right(phoneno,4) =e.extension


HTH


--------------------------------------------------------------
Go to Top of Page

spanki
Starting Member

8 Posts

Posted - 2002-05-19 : 05:22:28
if i had a colomn employee_name in the same table as extn.. would i have to compare the exn name agaisnt the employee_name to acheice a list of calls by name?


Go to Top of Page

Nazim
A custom title

1408 Posts

Posted - 2002-05-19 : 09:43:29
Nopes a Group by clause on name will help you.



select EmployeeName,count(1) as CountofCalls from phonebook p
inner join extensiontable e
on p.right(phoneno,4) =e.extension
group by e.Employeename

Will give the list of calls by Name


select EmployeeName,Right,e.extension,count(1) as CountofCalls from phonebook p
inner join extensiontable e
on p.right(phoneno,4) =e.extension
group by e.Employeename,e.extension

will give you calls grouped by Name and extension(sub Grouped).


i will suggest you to pick a SQL for Dummies.

Read Select, Group by, Joins from BOL too.

HTH


--------------------------------------------------------------
Go to Top of Page

spanki
Starting Member

8 Posts

Posted - 2002-05-19 : 10:19:12
cheers!


Go to Top of Page
   

- Advertisement -