简体   繁体   English

本月至今查询

[英]Month to date query

How do I make a query run for current month and current day of that month? 如何使查询针对当前月份和该月的当前日期运行?

For example : 例如 :

Select 
    installed_date,
    cust_no,
    sum(Price) as daily_price
From 
    table1
Group By 
    installed_date, 
    cust_no

I want this query to always return current month's data so in this case from 1st Dec 2013 till 3rd Dec 2013 . 我希望此查询始终返回当前月份的数据,因此在这种情况下,从1st Dec 20133rd Dec 2013 1st Dec 20131st Dec 20133rd Dec 2013

Thanks 谢谢

select installed_date,cust_no,sum(Price) as daily_price
from table1
where installed_date >= dateadd(month, datediff(month,0, current_timestamp), 0)
group by installed_date,cust_no

Click on this link 点击此链接

Check above link. 检查上面的链接。
I have created a table with three column. 我创建了一个包含三列的表。 Schema of same is added to this link. 相同的架构已添加到此链接。 Also wrote a query which will resolve your problem. 还写了一个查询,将解决您的问题。 Have a look. 看一看。 I am not mysql developer but tried to convert mssql query to mysql. 我不是mysql开发人员,但尝试将mssql查询转换为mysql。 If you want MSSQL query then revert. 如果要MSSQL查询,请还原。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM