sql - Why would the query show data from the wrong month? -
I have a question: So doing some testing, I have a few columns To change the data, to see if that gives me some information, I do not know that when I run the query, it returns my date column which is not as "photo" below the "Jan" (line 4) Should be: There is more data in the database, whose exact exact date is '2014-01-25 00: 00: 00.000', so I'm not sure how will it achieve just that line and compare the average? Before I ran the query, changed that column to that line and changed the date? But I'm not sure that would do something with it Update: I sqlfinddle, I have added it want to achieve an average reduction of last_month - before the last 2 months. . It was working till I made no changes and changed the data. I made changes to test a certain position, which clearly leads to learning that the query has flaws. On the basis of its SQL Fiddle, this has been linked to the first month -2 goes.
, as well date_cte (r.starburst_dept_name select, R, as a priority, as Purhwarekha, primarily x.monthly_past_date, r.starburst_dept_average - x.starburst_dept_average - x.starburst_dept_average in (select average *, the ROW_NUMBER () (by order monthly_past_date according Starbrst_dipt_nam ) intranet Dibo Sisi_reprs_moth of RID R) *, ROW_NUMBER (more) intranet.dbo.cse_reports_month go months (monthly_past_date) & gt as Rowid (D Order starburst_dept_name by by monthly_past_date PARTITION); r.starburst_dept_name = x x months (DATEADD (m, -2, monthly_past_date))). starburst_dept_name and r.rowid = x.rowid +1 where r.starburst_dept_name select average DESC by minus date_cte order) * Not
select thismonth.starburst_dept_name, lastmonth.monthtly_past_date [PrevDate], thismonth.monthtly_past_date [CurrDate], thismonth.starburst_dept_average - lastmonth.starburst_dept_average as average dbo.cse_reports included within this month To be dbo.cse_reports lastmonth thismonth.starburst_dept_name = lastmonth.starburst_dept_name and month (DATEADD (month, -1, thismonth.monthtly_past_date)) = month (lastmonth.monthtly_past_date) Where month (thismonth.monthtly_past_date) = months (DATEADD (MONTH, -1, GETDATE ())) ordered by thismonth.starburst_dept_average - lastmonth.starburst_dept_average DESC
Comments
Post a Comment