?
Solved

fetching data from last 5 days

Posted on 2013-05-22
5
Medium Priority
?
189 Views
Last Modified: 2013-05-22
hi guys

i have a table Sale_Region like


sale_Date   region    customer_name

2013-05-19     UK                  Jay
2013-03-1      US                  Jack
2013-05-22     AUS                 Jill
2013-05-21     UK                  Anthony



I want to return three columns max(sale_Date) , sale_Date which is 5 working days before  max(sale_Date),
region from the table

any idea how i can do that?



thanks
0
Comment
Question by:royjayd
[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
  • 3
  • 2
5 Comments
 

Author Comment

by:royjayd
ID: 39187874
any answers greatly appreciated
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 1660 total points
ID: 39187918
Give this a whirl..

SELECT region, customer_name, max(sale_date), DATEADD(dd, -5,  max(sale_date)) as sale_date_minus_five_days
FROM YourTable
GROUP BY region, customer_name
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39187928
'working days'

How does your company define this?  Most companies will have a custom table where each day is a row, and columns for fiscal year/month/week/whatever, working days, etc.

Problem is, everyone has different holdiays, so what's a working day will vary wildly between companies and countries, such that a single SQL function won't cover all situations.
0
 

Author Comment

by:royjayd
ID: 39188014
jim

I think that sql is pretty good and i agree with your point about working days , our users are in US and UK.

thanks.
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39188055
Thanks for the grade.  Good luck with your project.  -Jim

btw a TIME table is invaluable imho, for dealing with not only working days, but if your company has a really screwed up fiscal year such as crop year / federal year, and if fiscal months are 4-5-4 instead of straight calendar months.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

762 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