2014-09-22 84 views
0

分组生日按月份

select DATE_FORMAT(geboren, "%m (%M)") as 'geboortemaand', count(geboren) as 'aantal medewerkers' 
 
from medewerkers 
 
group by 1 
 
order by month(geboren)

我想通过自己的birthmonth过滤员工做出一个初步的名单。 目前我有它,因为它应该是,除了它的一般外观。

月份表示法目前看起来像这样...

2(月)|生日数量

3(三月)|生日

量等

它需要像这样...

02(月)|生日数量

03(三月)|生日数量

但不仅仅是数字是一个问题,我还试图将月份编号/名称与表格的左侧对齐,而不是默认的右侧。

编辑: 我通过切换concat与DATE_FORMAT(geboren,“%m(%M)”),固定了日期问题。

但现在如何将文本对齐到左侧?

+1

我可能只是将它排序在一个数组中。 http://stackoverflow.com/questions/12424968/php-re-order-array-of-month-names – user2075215 2014-09-22 14:34:09

回答

0

可以使用LPAD函数到一个月零垫......

select concat(lpad(month(geboren),2,'0') ,' (',monthname(geboren),')') as 'geboortemaand', count(geboren) as 'aantal medewerkers' 
from medewerkers 
group by month(geboren) 

也可以仅仅通过月龄组()函数直接,其分类结果为好,一般可以进行一点点更好。