赞
踩
- SELECT
- E1.id,
- E1.month,
- (IFNULL(E1.salary, 0) + IFNULL(E2.salary, 0) + IFNULL(E3.salary, 0)) AS Salary
- FROM
- (SELECT
- id, MAX(month) AS month
- FROM
- Employee
- GROUP BY id
- HAVING COUNT(*) > 1) AS e
- LEFT JOIN
- Employee E1 ON (e.id = E1.id
- AND e.month > E1.month)
- LEFT JOIN
- Employee E2 ON (E2.id = E1.id
- AND E2.month = E1.month - 1)
- LEFT JOIN
- Employee E3 ON (E3.id = E1.id
- AND E3.month = E1.month - 2)
- ORDER BY id ASC , month DESC
- ;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。