总结查询的结果 [英] Sum up a result from a query
问题描述
大家好,我在商务中退出新品,我有一个查询,结果是每天4个不同样品的价值。现在在同一个查询中我想在同一天添加所有值并保存为新的列名。任何人都可以帮我完成我的查询。
这里的结果是:
它是一个月的标记名日,值
0200_P1511_TPV 27 762
0200_P1521_TPV 27 2492
0200_P3010_TPV 27 2927
0200_P3020_TPV 27 2337
这是给我这个结果的查询:
SELECT
parameterColumn,
DATEPART( DD,dateTimeColumn) AS day1,
SUM( CONVERT ( float ,valueColumn)) as value
FROM [dbo]。[mydbname]
其中 [dateTimeColumn]> ' 2019-05-19 08:00:00.000'
和([parameterColumn] = ' 0200_P1511_TPV'
< span class =code-keyword>或 [parameterColumn] = ' 0200_P1521_TPV'
或 [parameterColumn] = ' 0200_P3010_TPV'
或 [parameterColumn] = ' 0200_P3020_TPV')
组 按 DATEPART(Day,dateTimeColumn),[parameterColumn]
order by [day1 ] desc
现在我想要一个新的列n总结了第27天和所有其他日子的所有价值。
最好的问候,emilio
我尝试了什么:
我在问题描述中写的内容
如果您真的对学习SQL感兴趣而不仅仅是要求答案,那么您应该学会将复杂查询分解为多个更简单的链式查询为了理解发生了什么。
https://www.datacamp。 com / community / tutorials / sql-tutorial-query [ ^ ]
hi all, im quit new in the buisness and i have a query and the result is value per day from 4 different samples. now in the same query i would like to add all the value on the same day and save as a new column name. can anyone help me finisch my query.
here is the result:
its a tagname day of the month and value
0200_P1511_TPV 27 762
0200_P1521_TPV 27 2492
0200_P3010_TPV 27 2927
0200_P3020_TPV 27 2337
this is the query that gives me this result:
SELECT
parameterColumn,
DATEPART (DD, dateTimeColumn) AS day1,
SUM(CONVERT(float,valueColumn)) as value
FROM [dbo].[mydbname]
where [dateTimeColumn] > '2019-05-19 08:00:00.000'
and ( [parameterColumn] = '0200_P1511_TPV'
or [parameterColumn] = '0200_P1521_TPV'
or [parameterColumn] = '0200_P3010_TPV'
or [parameterColumn] = '0200_P3020_TPV')
Group By DATEPART (Day, dateTimeColumn), [parameterColumn]
order by [day1] desc
Now I would like a new column where all the value of day 27 and all other days are summed up.
best regards, emilio
What I have tried:
What I have written in the problem description
If you're actually interested in "learning SQL" instead of just asking for "the answer", you should learn to decompose "complex" queries into multiple simpler "chained" queries in order to understand what is going on.
https://www.datacamp.com/community/tutorials/sql-tutorial-query[^]
这篇关于总结查询的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!