General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

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 14th, 2013, 10:47 PM
BooBooDaddy BooBooDaddy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 2 BooBooDaddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 57 sec
Reputation Power: 0
Max (date) and Count Help

I need to return a listing that shows for the maximum date or current date - the Part, Expeditor, Forecast, DOS, and the number of times
that the part has appeared in the data (not just for the max date, but for the entire history of the part in the data) from the dataset
called PartLevelDetail

Part Expeditor Forecast DOS # Occurances
1234 A 100 3 5
4567 A 233 2 5
5443 C 222 3 3
9887 D 235 4 1

I am new to SQL. Can anyone help out a newbie?

Reply With Quote
  #2  
Old March 16th, 2013, 07:39 PM
bitsmed bitsmed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 11 bitsmed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 59 m 53 sec
Reputation Power: 0
Hi,

Replace "thedate" with the name of the date field in your table:
Code:
select a.part
      ,b.expeditor
      ,b.forecast
      ,b.dos
      ,a.partcount
  from (select part
              ,max(thedate) as maxdate
              ,count(part) as partcount
          from partleveldetail
         group by part
       ) as a
       inner join partleveldetail as b
               on b.part=a.part
              and b.thedate=a.maxdate
 order by a.part

Reply With Quote
  #3  
Old March 18th, 2013, 07:49 AM
BooBooDaddy BooBooDaddy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 2 BooBooDaddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by bitsmed
Hi,

Replace "thedate" with the name of the date field in your table:
Code:
select a.part
      ,b.expeditor
      ,b.forecast
      ,b.dos
      ,a.partcount
  from (select part
              ,max(thedate) as maxdate
              ,count(part) as partcount
          from partleveldetail
         group by part
       ) as a
       inner join partleveldetail as b
               on b.part=a.part
              and b.thedate=a.maxdate
 order by a.part




Thank you for your help

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Max (date) and Count Help


Developer Shed Advertisers and Affiliates


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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap