Avatar of ariking
arikingFlag for United States of America

asked on 

SQL or Excel

The data below is from an Oracle table. I want to get the right date_req for each group of rcvr. The following is the conditions,

If calc is a decimal number, use the corresponding date_req
If the above condition is false then check calc for "1" and get the maximum date_req
Calc is qty_rec divided by qty_ord.  Possible value for calc is 0, 1 and a decimal number.
There can only be one decimal number (if exist) for each group of rcvr.

The last 2 line below is the result we need. Using SQL is the prefer method. Although, we can use Excel solution as a last resort. Appreciate the help.

rcvr      date_req      qty_ord      qty_rec      calc
a      1/1/2008      10      10      1
a      2/1/2008      20      5      0.25
a      4/1/2008      25      0      0
a      6/1/2008      30      0      0
b      7/1/2008      5      5      1
b      8/1/2008      10      10      1
b      1/1/2009      15      15      1
b      3/1/2009      20      0      0
b      4/1/2009      25      0      0
b      6/1/2009      30      0      0
b      7/1/2009      35      0      0
b      9/1/2009      40      0      0

Results
a      2/1/2008      20      5      0.25
b      1/1/2009      15      15      1
Microsoft ExcelSQL

Avatar of undefined
Last Comment
julienwood
ASKER CERTIFIED SOLUTION
Avatar of julienwood
julienwood

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of julienwood
julienwood

BTW, it is SQL SERVER 2005
Try not to use excel, it makes things very massy
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo