一个月的SQL选择 [英] Sql selection for month

查看:96
本文介绍了一个月的SQL选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个月的报告



我创造了一天...



需要修理mont



一些帮助



我尝试了什么:



I need to create report for month

I have created for one day...

Need to repair for mont

Some help

What I have tried:

select datum as Datum, SUM (Try_Convert(float,[iznos_sa_pdv])) as UKUPNO
from mp_kasa_lista
where [datum] >= CONVERT(datetime, convert(varchar(10), GETDATE() ,120), 120)
AND   datum <  DATEADD(day, 1, convert(datetime, convert(varchar(10), getdate(), 120), 120)) and tip_placanja='Virman'
group by datum

推荐答案

GROUP BY 组合完全匹配 的值 - 所以甚至千分之一秒的值都将在不同的组中。



要对一个月的值进行分组,您需要在SELECT中指定月份然后使用命令的GROUP BY部分。

你可以通过使用DATEPART从DATETIME值中减去月中的某一天来将它们规范化到该月的第1天,然后转换它们DATE以消除任何时间部分。

或使用DATEPART提取月份和年份并使用它们。
GROUP BY combines values which match exactly - so values which differ by even 1,000th of a second will all be in separate groups.

To group value for a month, you need to specify the month in both the SELECT and thge GROUP BY parts of the command.
You can do that by using DATEPART to subtract the day of the month from the DATETIME value to "normalize" them to the 1st of the month, then convert them to DATE to eliminate any time part.
Or use DATEPART to extract the month and year and use those instead.


您可以通过使用MONTH(返回表示指定日期月份的整数):

You can do that by using MONTH (Returns an integer that represents the month of the specified date):
select datum as Datum, SUM (Try_Convert(float,[iznos_sa_pdv])) as UKUPNO
from mp_kasa_lista
where MONTH([datum]) = MONTH(GETDATE()) and tip_placanja='Virman'
group by datum


这篇关于一个月的SQL选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆