我有一些表格,需要在每个日期的一行上获取每日生产值的组合(总和),以计算该部门在每个唯一日期的总产量。下面的 t-SQL 代码返回单独的行,如我粘贴在查询下方的结果所示。
USE CPR
CREATE TABLE [dbo].[CPR_TotalDailyHygieneProd1845] (
[HygienistReportDate] [DATETIME] NULL,
[TotalDailyHygieneProd] [MONEY] NULL)
Insert INTO dbo.CPR_TotalDailyHygieneProd1845 (
HygienistReportDate,
TotalDailyHygieneProd)
SELECT DISTINCT
CAST(dbo.tHygienistStats.ReportDate AS DATE),
SUM(dbo.tHygienistStats.DailyHygieneProd) AS TotalDailyHygieneProd
FROM dbo.tHygienistStats
WHERE dbo.tHygienistStats.PracticeID = '1845'
GROUP BY
dbo.tHygienistStats.ReportDate,
dbo.tHygienistStats.DailyHygieneProd
GO
HygienistReportDate TotalDailyHygieneProd
2024-07-19 00:00:00.000 549.00
2024-07-19 00:00:00.000 1291.00
2024-07-19 00:00:00.000 1351.00
2024-07-19 00:00:00.000 1501.00
2024-07-18 00:00:00.000 909.00
2024-07-18 00:00:00.000 1092.00
2024-07-18 00:00:00.000 1228.00
2024-07-18 00:00:00.000 1342.00
2024-07-18 00:00:00.000 1518.00
2024-07-17 00:00:00.000 0.00
2024-07-17 00:00:00.000 953.00
2024-07-17 00:00:00.000 1223.00
2024-07-17 00:00:00.000 1431.00
2024-07-17 00:00:00.000 1783.00
请参阅我上面粘贴的示例。
自己的问题解决了,希望对其他人有帮助。我从 GROUP BY 子句中删除了 dbo.tHygienistStats.DailyHygieneProd。