请更正我的查询

时间:2012-06-25 12:48:05

标签: sql-server-2005

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

请帮助

1 个答案:

答案 0 :(得分:3)

假设您要SUM小时和分钟列,则必须从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