2014-09-22 115 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) 

也可以僅僅通過月齡組()函數直接,其分類結果爲好,一般可以進行一點點更好。