Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Select count

Posted on 2014-03-13
2
Medium Priority
?
418 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

721 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