473,404 Members | 2,114 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,404 software developers and data experts.

Query to Sum Values from the Same Month in Different Years

How can I make a query where will be comparison sales of products between (only) january 2006 and january 2007.
I have one table with following data:
Expand|Select|Wrap|Line Numbers
  1. salesdate   products   quantity    price
  2. 01/01/2006   apples     100           20
  3. 05/01/2006   pears        50            15
  4. 07/01/21007  apples      35            20
for an example.I would like to see how much sold apples in january 2006 and how much in january 2007
Feb 23 '07 #1
1 1815
nico5038
3,080 Expert 2GB
try:
SELECT salesdate, products, Year(salesdate) & right('00' & Month(salesdate),2) as YearDate, Sum(IIF(Year=2006,quantity*price,0)) as YearAmount2006, Sum(IIF(Year=2007,quantity*price,0)) as YearAmount2007
FROM tblSales
WHERE products = 'apples'
GROUP BY salesdate, products, Year(salesdate) & right('00'&Month(salesdate),2)
HAVING Year(salesdate) & right('00' & Month(salesdate),2) IN ('200601','200701')

Getting the idea ?

Nic;o)
Feb 25 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: rong.guo | last post by:
Hello group! I am having a problem with simplying my query... I would like to get customers' balance info based on how many months since they opened their accounts. The tricky part here is...
5
by: Bill | last post by:
Good Day; I would appreciate assistance developing a query that I haven't been able to develop without using a second table. I wish to count the number of records that are still open on the...
2
by: Jerry | last post by:
Hi, Access 2003. I would like to query specific dates or years. I need to be able to selct the dates in a query, ie aug 12 2004, aug 11th 2004, or 2001, 2002 and 2003. Any help is most appreciated
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
5
by: jonm4102 | last post by:
I'm trying to calculate the median of some numerical data. The data can only be found in a query (henceforth query 1) field I previously made, and I would prefer to calculate the median in a new...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
5
by: veaux | last post by:
I'm thinking this is easy but can't get it. I have a table with following: Table1 Date 1/1/2007 Table2 Type 0107 (This is MMYY of above) So I'm having trouble using a query to turn the...
2
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
2
by: Dinesh | last post by:
Hi experts, I am working on SQL server 2005 reporting services and i am getting a problem in writting a query. Situation is given below. There is one table in database Named Child Now i...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.