This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Get Sum of column and the retrive the data month wise. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Get Sum of column and the retrive the data month wise." Watch "Get Sum of column and the retrive the data month wise." New topic

Get Sum of column and the retrive the data month wise.

Mayur Saparia

Joined: Feb 13, 2013
Posts: 19

I have a table which has product quantity column and the database has multiple entries in a single month.
For eg:
Date is in string format as i have used JXDatePicker so i was unable to store date in Date type in mySql .
Date format is (yyyy-MM-dd)
2013-03-01 > 1200 (This is product quantity)
2013-03-05 >200

2013-04-05 > 500
2013-04-10 > 1000

2013-05-05 > 850
2013-05-10 > 50

so i want data as

for March(2013-03-01 to 2013-03-31) > SUM OF product i.e : 1400.
April (2013-04-01 to 2013-04-30) > SUM OF product i.e : 1500.
May (2013-05-01 to 2013-05-31) > SUM OF product i.e : 900.

also i have different kind of propducts so i will be getting it according to product , For example purpose consider this records are ONLY FOR Product 'A' of Customer 'XYZ', So please consider this in where clause.

I have tried getting the data month wise using query as follows:

and i get the data as follows

the date format have changed because I have pasted it from Excel but please keep the date format as mentioned above.

SrNo delivery reciept no. delivery recipet date material received on customer name customer ID product name product ID quantity of product comments
1 bc-123 3/2/2013 3/5/2013 xyz 1 a 1 1500 1500 received
2 bc123123 1/3/2013 1/6/2013 xyz 1 a 1 123 asdfasf
3 bvc1234 2/7/2013 2/12/2013 xyz 1 a 1 1234 asdfasdf
6 bc123423 4/10/2013 4/19/2013 xyz 1 a 1 454 asdfasd
7 bc12343 5/1/2013 5/9/2013 xyz 1 a 1 456 asdfasdf
8 bc12345 6/18/2013 6/19/2013 xyz 1 a 1 1200 asdfasd
9 bc123-45 3/14/2013 3/26/2013 xyz 1 a 1 120 adsfasdf

This is the actual data from my database where i have 2 entries of March 3/2/2013 > 1500 & 3/14/2013 > 120 so i want the sum of it and not differently displaying both the records.

Thanks In advance

T Mishra
Ranch Hand

Joined: Apr 04, 2006
Posts: 108

Duplicate post

Tushar (SCJP 1.5)
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Get Sum of column and the retrive the data month wise.
It's not a secret anymore!