473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Orderdatabase - Difference in sale from one year to another - SQL?

I have an orderdatabase with DATE and SALES as one of the fields in a
table. How would the SQL look like if I want a table with MONTH, 2006,
2005, DIFFERENCE. I think when I have the field DATE I can get month
and the year.

Thanks
Helge

Jun 25 '06 #1
1 1284
Helge's wrote in message
<11**********************@y41g2000cwy.googlegroups .com> :
I have an orderdatabase with DATE and SALES as one of the fields in a
table. How would the SQL look like if I want a table with MONTH,
2006, 2005, DIFFERENCE. I think when I have the field DATE I can get
month and the year.

Thanks
Helge


Hei Helge!

I guess there are lot of possibilities for this. Here's one quickly
thrown together suggestion which includes an integer table containing
(integer) numbers 1-N.

select monthname(i.id),
(select sum(SALES) from YourTable where Year(YourDate) =
Year(Date()-1) and Month(YourDate) = i.id) as s2005,
(select sum(SALES) from YourTable where Year(YourDate) =
Year(Date()) and Month(YourDate) = i.id) as s2006,
(select sum(SALES) from YourTable where Year(YourDate) =
Year(Date()) and Month(YourDate) = i.id) -
(select sum(SALES) from YourTable where Year(YourDate) =
Year(Date()-1) and Month(YourDate) = i.id)
from tblIntegers i
where i.ID <= 12
order by i.id

You might need usage of the NZ function, too, should any of them be
Null

--
Roy-Vidar
Jun 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hans Gruber | last post by:
Hi all, I have been struggling with a problem all day, I have been unable to come up with a working solution. I want to write a function which takes 2 unix timestamps and calculates the...
26
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: ...
10
by: Michel | last post by:
Hi, We are from Belgium and are looking for someone who could write us a point-of-sale (POS) software for a DVD-film shop. I like it to be in MS-Access with some VBA or just VB. The...
6
by: Ashish Sheth | last post by:
Hi All, In C#, How can I get the difference between two dates in number of months? I tried to use the Substract method of the DateTime class and it is giving me the difference in TimeSpan,From...
5
by: Simon Dean | last post by:
Probably being a little thick here, but when you subtract one date away from another, how do you convert the resultant value into a number of days... I guess I could easily / 60 / 60 / 24... but...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
23
by: thebjorn | last post by:
For the purpose of finding someone's age I was looking for a way to find how the difference in years between two dates, so I could do something like: age = (date.today() - born).year but that...
2
by: Phlip | last post by:
XMLers: Try this failing test: assert_xml '<html> <form class=\'for_"sale"\' /> </html>' assert_tag_id :form, :class ='for_"sale"'
15
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.