SUM week with doctrine
March 2012:
9 27 28 29 1 2 3 4
10 5 6 7 8 9 10 11
11 12 13 14 15 16 17 18
12 19 20 21 22 23 24 25
13 26 27 28 29 30 31
The first column is the week number of the year - in php date ("W") ; I have in my MySQL database:
id | count | date
1 | 2 | 2012-02-28 11:11:11 // 9 week
2 | 4 | 2012-02-29 11:11:11 // 9 week
3 | 5 | 2012-03-01 11:11:11 // 9 week
4 | 2 | 2012-03-03 11:11:11 // 9 week
5 | 5 | 2012-03-05 11:11:11 // 10 week
6 | 3 | 2012-03-07 11:11:11 // 10 week
7 | 6 | 2012-03-08 11:11:11 // 10 week
8 | 2 | 2012-03-12 11:11:11 // 11 week
9 | 6 | 2012-03-13 11:11:11 // 11 week
10 | 5 | 2012-03-16 11:11:11 // 11 week
11 | 1 | 2012-03-16 11:11:11 // 11 week
12 | 9 | 2012-03-16 11:11:11 // 11 week
How can I SUM with Symfony 1.4 and Doctrine 1.2 for the whole week?
In this example, I have to show:
week | count
9 | 13
10 | 14
11 | 23
How do I search for a query using Doctrine?
+3
source to share
2 answers
According to this http://sqlfiddle.com/#!2/9701b/6 I'll execute this query:
$query = Doctrine_Query::create()
->select("sum(s.count), date_format(s.date, '%v') as date_formatted")
->from('SomeTable s')
->groupBy('date_formatted');
I used as date_formatted
select in the clause because Doctrine doesn't understand date_format
in the method groupBy
.
+13
source to share