General sql query question (compare date ranges)

Dave_be
Member Posts: 35
I'm trying to create a report true SQL BI that compares the sales of a product/customer between two given date frames.
For example, I want to see the difference in sale from item "111" from (01/01/2008 till 31/12/2008) and (01/01/2009 until 31/01/09.)
All data is in the same table, so no external joins are needed.
Data output must give something like this:
Any help would be highly appreciated
For example, I want to see the difference in sale from item "111" from (01/01/2008 till 31/12/2008) and (01/01/2009 until 31/01/09.)
All data is in the same table, so no external joins are needed.
Data output must give something like this:
Item Date 1 Date 2 Difference 111 2000 1000 -100%But the second thing is, when date 1 has no data for the period it still must show date 2.
Item Date 1 Date 2 Difference 111 0 1000 100%I just can't seem to get this in my head and this is really frustrating me for quite some time now.
Any help would be highly appreciated
0
Comments
-
Use a left outer join between the two parts of your query. This way it returns an item only if it has data for the first range.There are no bugs - only undocumented features.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions