mysql按年份查找基于日期的结果

时间:2014-08-21 06:10:25

标签: mysql

SELECT SUM(case when c_gender='Male' then 1 else 0 end) as Male, SUM(case when c_gender='Female' then 1 else 0 end) as Female , count(*) as tot , FROM_UNIXTIME(c_admissionDate, '%Y') as year FROM `student` where FROM_UNIXTIME(`c_admissionDate`, '%m') group by year

我的数据 学生表

gender   admissiondate     leaving date
 male     1375813800         1407781800   
 female   1344277800         1408473000
 female   1344277800         null
 female   1344277800         1407781800  

想要找到计数总和

计数总和=按年计算的所有入学日期的总和 - 按年份计算的离职日期总和

我需要像

这样的结果
year male female admission leaving total
2014  2      1      3         1      2
2013  10     2     12         3      9

0 个答案:

没有答案