Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 2nd, 2007, 12:25 PM
wambawamba wambawamba is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 1 wambawamba User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 40 sec
Reputation Power: 0
Group by

I want to change the following query so that a Sub_Id will be counted in a particular category ONLY if it is the last Sub_ID entered during the given time period. I believe I need a Select Top and/or Group by DESC subquery, but I'm unfamiliar.

SELECT
'Misc Calls' AS Heading,
CASE Sub_Id
WHEN 202142 THEN 'Incomplete Info'
WHEN 202373 THEN 'General Info'
WHEN 201933 THEN 'Workshop'
WHEN 202366 THEN 'No Longer Interested'
WHEN 202367 THEN 'Unable to Reach'
END AS Category,
COUNT(DISTINCT c.Business_Id) AS CategoryCount
FROM
Contacts c
INNER JOIN Businesses b ON b.Business_Id = c.Business_Id
WHERE
YEAR(b.OpenedDate) = 2007 AND
MONTH(b.OpenedDate) = 1 AND
(Sub_Id = 202142 OR Sub_Id = 202373 OR Sub_Id = 201933 OR Sub_Id = 202366 OR Sub_Id =202367)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Group by


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT