select RIGHT("timeline".id,2) AS "timeline_day_nb_full", COUNT(DISTINCT("orderfact".ordernumber)) AS "orderfact_ordernumber" from orderfact "orderfact", timeline "timeline" where "orderfact".time_id="timeline".id AND LEFT("timeline".id,7)='2012-12' group by RIGHT("timeline".id,2) order by "timeline_day_nb_full", "orderfact_ordernumber"