Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Select count

Posted on 2014-03-13
2
Medium Priority
?
423 Views
Last Modified: 2014-03-13
Hello,
Can you please help,
I need to get the Operator count per city.
this is my Select Statment,

Select case when Operator like 'WEB' THEN 'WEB' ELSE 'CSR' END AS [Oprator],
case when (Select AccountCode from Clients where Clients.AccountNumber = finalizedorders.AccountNumber) Like 'T%' THEN 'Toronto'
when (Select AccountCode from Clients where Clients.AccountNumber = finalizedorders.AccountNumber) Like 'O%' THEN 'Ottawa'
when (Select AccountCode from Clients where Clients.AccountNumber = finalizedorders.AccountNumber) Like 'B%' THEN 'Ottawa'
when (Select AccountCode from Clients where Clients.AccountNumber = finalizedorders.AccountNumber) Like 'H%' THEN 'Halifax'
when (Select AccountCode from Clients where Clients.AccountNumber = finalizedorders.AccountNumber) Like 'K%' THEN 'Waterloo'
when (Select AccountCode from Clients where Clients.AccountNumber = finalizedorders.AccountNumber) Like 'V%' THEN 'Vancouver'
Else 'Montreal' END as [City]
FROM finalizedorders WHERE ((OrderDate >= '2014-01-01')) and AccountNumber not in (3333,3334,3335)
Order by City,Operator


Thanks for your help.
0
Comment
Question by:W.E.B
2 Comments
 
LVL 27

Accepted Solution

by:
Shaun Kline earned 1200 total points
ID: 39927247
If your SQL is providing you with the correct raw data, you can wrap it (minus the order by) in a select statement:

SELECT Operator, City, COUNT(*)
from (<your query>) As RawData
group by Operator, City
Order by City, Operator

(Assuming that Oprator is just mistyped.)
0
 

Author Closing Comment

by:W.E.B
ID: 39927283
Excellent,
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question