0

如何将两行合二为一。

EMPCode  actHours    actDate     rowno
107 8.00        2013-01-21  1
107 8.30        2013-01-22  1
107 4.00        2013-01-23  1
107 4.00        2013-01-23  2
107 4.10        2013-01-24  1
107 4.20        2013-01-24  2
107 4.30        2013-01-25  1
107 4.30        2013-01-25  2

I want the result as follows:

actHours    actDate 
8.00        2013-01-21 
8.30        2013-01-22
8.00        2013-01-23 
8.30        2013-01-24
9.00        2013-01-25  

任何帮助将不胜感激。提前致谢 :-)

4

3 回答 3

2

尝试这个:

SELECT SUM(actHours) actHours, actDate FROM Tbl GROUP BY actDate

实际上,如果您提供列的数据类型,答案可能会更具体。

于 2013-03-26T10:42:52.577 回答
0

然后用这个,

with datecte
as
(
 select  actDate, SUM(DATEDIFF(MINUTE, '0:00:00', actHours)) actHours
 from (
   SELECT actDate,CAST(REPLACE(actHours,'.',':') as time) actHours
   FROM #tb1
      ) k 
 group by actDate
)


SELECT actDate,
actHours = RTRIM(actHours/60) + ':' + RIGHT('0' + RTRIM(actHours%60),2)
FROM datecte

希望这能给你解决方案..

好的@praveen ..

于 2013-03-26T13:05:04.920 回答
0

如果数据包含这些怎么办..

108 3.40        2013-01-26  1
108 3.50        2013-01-26  2

如果数据类型是time,那么你可以使用这个查询..

with datecte
as
(
 SELECT actDate,  SUM(DATEDIFF(MINUTE, '0:00:00', actHours)) actHours
 FROM Tb1
 GROUP BY actDate
)
SELECT actDate,
actHours = RTRIM(actHours/60) + ':' + RIGHT('0' + RTRIM(actHours%60),2)
FROM datecte
于 2013-03-26T11:31:43.930 回答