also, kleine sache noch:
ich stehe jetzt vor dem problem, das ein "Andreas Kretschmer" 2004 gehabt hat, zumindest laut google... 
fogender code:
Code:
select city_id, count(id) as bestellungen,
to_char(submitted_at,'yyyy mm') as wann
from cart_order where city_id in ( select city_id from (select
sum(case when ( to_char(submitted_at,'yyyy mm')='2011 01') then 1 else 0 end) as anfang,
sum(case when ( to_char(submitted_at,'yyyy mm')='2011 07') then 1 else 0 end) as ende ,
city_id from orders group by city_id ) foo
where anfang>0 and ende>0 order by cast( ende as float)/cast(NULLIF(anfang,0)as float) desc limit 10 )
group by city_id, wann
order by wann,city_id
ergibt
20 | 12 | 2011 01 |
544 | 12 | 2011 01 |
679 | 2 | 2011 01 |
680 | 3 | 2011 01 |
686 | 4 | 2011 01 |
688 | 13 | 2011 01 |
876 | 1 | 2011 01 |
877 | 1 | 2011 01 |
908 | 4 | 2011 01 |
1082 | 15 | 2011 01 |
20 | 11 | 2011 02 |
544 | 12 | 2011 02 |
679 | 2 | 2011 02 |
680 | 1 | 2011 02 |
686 | 2 | 2011 02 |
688 | 14 | 2011 02 |
876 | 1 | 2011 02 |
908 | 5 | 2011 02 |
usw usw
ergeben sollte es eine tabelle
| city_id | 2011 01 | 2011 02 | 2011 03 | usw,dynamisch |
| 20 | 12 | 11 | ... | |
| 544 | 12 | 12 | ... | |
| 679 | 2 | 2 | 0 | |
| usw | ... | ... | ... | ... |
wobei, wie rot markiert, auch 0 als 0 eingetragen werden soll.
die frage dannach ist auf diversen foren verteilt, aber die antwort habe ich nicht gefunden...
Lesezeichen