943,659 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Marked Solved
  • Views: 1530
  • MySQL RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 10th, 2008
0

Query Needed

Expand Post »
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.
Similar Threads
Reputation Points: 5
Solved Threads: 5
Junior Poster
vssp is offline Offline
197 posts
since Jul 2006
Sep 10th, 2008
0

Re: Query Needed

can u post your table structure...
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Sep 10th, 2008
0

Re: Query Needed

hi

Thanks for your reply

Table structure here

sql Syntax (Toggle Plain Text)
  1. CREATE TABLE IF NOT EXISTS `invoice` (
  2. `id` INT(11) NOT NULL AUTO_INCREMENT,
  3. `instance_id` INT(11) NOT NULL DEFAULT '0',
  4. `project_id` INT(11) NOT NULL DEFAULT '0',
  5. `user_id` INT(11) NOT NULL DEFAULT '0',
  6. `instance_category_tasks_master_id` INT(11) NOT NULL DEFAULT '0',
  7. `invoice_id` INT(11) NOT NULL DEFAULT '0',
  8. `hours` DOUBLE(3,2) NOT NULL DEFAULT '0.00',
  9. `DATE` DATE NOT NULL DEFAULT '0000-00-00',
  10. `pay_rate` DOUBLE(5,2) NOT NULL DEFAULT '0.00',
  11. `bill_rate` DOUBLE(5,2) NOT NULL DEFAULT '0.00',
  12. `billable` ENUM('yes','no') NOT NULL DEFAULT 'yes',
  13. `created_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  14. `created_ipaddress` VARCHAR(15) NOT NULL DEFAULT '',
  15. `updated_date` DATE NOT NULL DEFAULT '0000-00-00',
  16. `updated_ipaddress` VARCHAR(15) NOT NULL DEFAULT '',
  17. `active` CHAR(3) NOT NULL DEFAULT '',
  18. `timecard_id` INT(11) NOT NULL,
  19. PRIMARY KEY (`id`)
  20. )
Last edited by peter_budo; Sep 11th, 2008 at 5:40 am. Reason: Keep It Organized - please use [code] tags
Reputation Points: 5
Solved Threads: 5
Junior Poster
vssp is offline Offline
197 posts
since Jul 2006
Sep 10th, 2008
0

Re: Query Needed

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
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Sep 10th, 2008
0

Re: Query Needed

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

Any Idea
Reputation Points: 5
Solved Threads: 5
Junior Poster
vssp is offline Offline
197 posts
since Jul 2006
Sep 10th, 2008
0

Re: Query Needed

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:
mysql Syntax (Toggle Plain Text)
  1. SELECT YEAR,
  2. MONTH , sum( points ) AS points
  3. FROM t1
  4. GROUP BY YEAR,
  5. MONTH
it will print:
year month points
2000 01 8
2000 02 15
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Sep 10th, 2008
0

Re: Query Needed

i think you have to add one more column like month the you will calculate hours per month by using group by month column...
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Sep 10th, 2008
0

Re: Query Needed

Cool .Let em check and let you know any doubt
Reputation Points: 5
Solved Threads: 5
Junior Poster
vssp is offline Offline
197 posts
since Jul 2006
Sep 12th, 2008
0

Re: Query Needed

hello...have you checked it???
have you got solved your problem...???
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Sep 15th, 2008
0

Re: Query Needed

Yes I have checked and complete the task .Thanks for you.
Reputation Points: 5
Solved Threads: 5
Junior Poster
vssp is offline Offline
197 posts
since Jul 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: SQL help - flat select
Next Thread in MySQL Forum Timeline: Database import in Cpanel 11





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC