0
Select empno,sum(cast(substring(othours,0,3)as float)) as
Hour,sum(cast(substring(othours,4,5)as float)) as Minutes from tmstrans 
group by empno,othours

它显示如下数据

  • 1 , 10
  • 1 , 30
  • 2 , 10
  • 2 , 30

我需要如下数据

  • 1 , 40
  • 2 , 40

请帮忙

4

1 回答 1

3

假设您想要SUMHour 和 Minutes 列,您必须从子句中删除该othours列。GROUP BY像这样测试它:

SELECT empno,
       SUM(CAST(SUBSTRING(othours,0,3) AS float)) AS Hour,
       SUM(CAST(SUBSTRING(othours,4,5) AS float)) AS Minutes
FROM tmstrans 
GROUP BY empno
于 2012-06-25T12:58:08.620 回答