select a.时间 as '时间1',sum(a.来馆人数) as '来馆人数1' from ( SELECT datepart(hh, DataDatetime) as '时间',sum(PeopleNum) '来馆人数'
FROM dbo.SysAdditionalData INNER JOIN
dbo.SysLibrary ON dbo.SysAdditionalData.SysLibraryId = dbo.SysLibrary.ID INNER JOIN
dbo.SysCustDevice ON dbo.SysLibrary.ID = dbo.SysCustDevice.SysLibraryId group by datepart(hh, DataDatetime) union SELECT datepart(hh,D_Date) as '时间',sum(D_InNum) as '来馆人数' FROM dbo.SysAdditionalData INNER JOIN
dbo.SysCustData ON dbo.SysAdditionalData.ID = dbo.SysCustData.ID INNER JOIN
dbo.SysCustDevice ON dbo.SysCustData.SysCustDeviceId = dbo.SysCustDevice.ID group by datepart(hh, D_Date) )as a group by a.时间