Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Select all entries from last two months

I would like to select dynamically all entries from last two months, and without entering date range in my query.

Here is my simple code:

SELECT Customer_Name, Date FROM table_Customer; all data between last  two month

Thanks in advance for your help

SELECT
    ME.FullName,
    R.RuleDefaultName,
    PR.ObjectName,
    PR.CounterName,
    P.DateTime,
    P.SampleCount,
    P.MinValue,
    P.MaxValue,
    P.AverageValue,
    P.StandardDeviation
FROM
    Perf.vPerfHourly P
INNER JOIN vManagedEntity ME ON
    P.ManagedEntityRowId = ME.ManagedEntityRowId
INNER JOIN vPerformanceRuleInstance PRI ON
    P.PerformanceRuleInstanceRowId = PRI.PerformanceRuleInstanceRowId
INNER JOIN vPerformanceRule PR ON
    PRI.RuleRowId = PR.RuleRowId
INNER JOIN vRule R ON
    PRI.RuleRowId = R.RuleRowId
like image 221
kekimian Avatar asked Oct 20 '25 11:10

kekimian


1 Answers

SELECT Customer_Name, Dt
FROM table_Customer
where dt >= dateadd(day, -60, getdate())

Or

SELECT Customer_Name, Dt
FROM table_Customer
where dt >= dateadd(month, -2, getdate())

You should make sure not to use reserved keywords as column names.

Make sure you replace dt with the appropriate date column. The solution assumes you would need the previous 2 months data starting with the current date.

like image 65
Vamsi Prabhala Avatar answered Oct 22 '25 23:10

Vamsi Prabhala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!