Rene
Rene

Reputation: 642

MySQL query to return an avg price per month(get the month out of the date formated 2010-03-30 for example)

I have three tables...

Given the following tables I would like to know how to write a query to return all the book sorted by month and with a average price per month table (that would be something like SUM(invoices.total)/COUNT(invoices.total). I have a date field which has a format of 2010-03-30, and I would like to get the months out of if…so I can sort the sum by month. I'm using PHP and MySQL. Thank you in advance!

books

-call_started

books_chapters

-id

invoices

-id

-invoice_type

-chapters_id

-total

Upvotes: 0

Views: 451

Answers (1)

ddinchev
ddinchev

Reputation: 34673

I can not construct the full query from the schema in your question but you can group the results - GROUP BY(CONCAT(YEAR(date_field), MONTH(date_field))

If you elaborate or comment, I will improve my answer.

Upvotes: 1

Related Questions