Solved

SQL Select count

Posted on 2014-03-13
2
392 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:Wass_QA
2 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 300 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:Wass_QA
ID: 39927283
Excellent,
Thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now