954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Query Needed

Hi Friends

I am working to draw a graph . I need to get the data monthly, for example JAN total hours FEB total hours ,

How to write the query get the total values per month?

Advance thanks for your reply.

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

can u post your table structure...

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

hi

Thanks for your reply

Table structure here

CREATE TABLE IF NOT EXISTS `invoice` (
  `id` int(11) NOT NULL auto_increment,
  `instance_id` int(11) NOT NULL default '0',
  `project_id` int(11) NOT NULL default '0',
  `user_id` int(11) NOT NULL default '0',
  `instance_category_tasks_master_id` int(11) NOT NULL default '0',
  `invoice_id` int(11) NOT NULL default '0',
  `hours` double(3,2) NOT NULL default '0.00',
  `date` date NOT NULL default '0000-00-00',
  `pay_rate` double(5,2) NOT NULL default '0.00',
  `bill_rate` double(5,2) NOT NULL default '0.00',
  `billable` enum('yes','no') NOT NULL default 'yes',
  `created_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `created_ipaddress` varchar(15) NOT NULL default '',
  `updated_date` date NOT NULL default '0000-00-00',
  `updated_ipaddress` varchar(15) NOT NULL default '',
  `active` char(3) NOT NULL default '',
  `timecard_id` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
)
vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

hello vssp...
there is a function called SUM in mysql to calculate total of any numerical column...and if you want to calculate per month,then use limit by 30 days...or created_date < last day of month...
see this link for your reference:
http://www.tizag.com/mysqlTutorial/mysqlsum.php

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

I need the query for every month , I need the query to get the values every month.

Any Idea

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

hello see this example will help you:
t1 table having 4 columns like year,month,day,points...
year month day points
2000 01 01 1
2000 01 20 3
2000 01 02 5
2000 02 23 10

then here im calculting total point per month...
here is the query:

SELECT year,
MONTH , sum( points ) AS points
FROM t1
GROUP BY year,
MONTH

it will print:
year month points
2000 01 8
2000 02 15

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

i think you have to add one more column like month the you will calculate hours per month by using group by month column...

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

Cool .Let em check and let you know any doubt

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

hello...have you checked it???
have you got solved your problem...???

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

Yes I have checked and complete the task .Thanks for you.

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

Welcome...

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You