please tell me how the query should be compiled for the table with the following lines: January 2019, first week of January 2019, second week of January 2019 ... fifth week of January 2019, February 2019, first week of February, 2019 second week of February 2019 .... Fifth week of December 2019. The amount of goods sold will be displayed in columns. That is, in the line of the month - the number of sales for the whole month, in the line of the week - the number of sold only for this week.
Related
I have this script which is run on the 15th of every month. This script intends to automatically take the last date of the previous month in the format of 'YYYY-MM-DD'. Is there a sql statement to do that?
For example today is 15th January 2017. I will run my script and it will give me a date of 31th December 2016 in the format 2016-12-31.
If it is 15th December 2016, I will get 30th November 2016 in the format 2016-11-30.
Thank you
You can use curdate() - interval 1 month paired with last_day =)
select last_day(curdate() - interval 1 month) as 'last_day_last_month';
I am trying to create a weekly report (including grouping by WEEK(date)) where weeks start on Monday. However, Week 1 is always the first week any day of a new year occurs. For example if Jan 1st is a Friday, that is week one.
This doesn't seem to be consistent with MySQL mode options for WEEK():
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week
Based on the available options it only works if the week has 4 or more days (options 1 and 3) or the Monday is in the new year (options 5 and 7). Neither of these account for example week 1 of 2016:
Wk Mon Tue Wed Thu Fri Sat Sun
No.
1 28 29 30 31 1 2 3
Is there any way to order/number the week numbers in MySQL based on this custom week mode requirement?
I need to display the fiscal month based on a date field that I have.
Our fiscal year starts on January 1st and is a standard 4/4/5 week quarter with the final day of the year on 12/31 no matter the number of weeks in the last period so the fiscal month will not always align with the calendar year.
For example in 2015, the last day of fiscal January is 1/30/15, February is 2/27/15, & April is 4/3/15
Can this be done using a single MySQL query statement where it list me out put as
GIVEN_DATE
FISCAL_YEAR
FISCAL_QUARTER
FISCAL_WEEK
FISCAL_MONTH
I have a report in SSRS 2012 scheduled to run quarterly on a specific day i.e. 15th Jan, 15th Apr, 15th Jul & 15th Oct.
My shared schedule config is: Ticked 'Month', selected Jan, Apr, Jul & Oct, set 'On calendar day(s)' to '15'.
The schedule is displayed correctly but in fact runs on the 15th of each month.
Knowing these schedules are actually implemented using SQL Server Agent I inspect the job and find that the job in question has 4 schedules against it.
15th day of every 12 month starting on the 1 jan 2013
15th day of every 12 month starting on the 1 apr 2013
15th day of every 12 month starting on the 1 jul 2013
15th day of every 12 month starting on the 1 oct 2013
so that also makes sense.
Is there a fix to this issue?
I think the problem (and solution) is the same as described here https://techcommunity.microsoft.com/t5/System-Center-Blog/Support-Tip-Scheduled-backup-to-tape-runs-on-a-wrong-date-on-DPM/ba-p/347075
looking to organize the following dates (assuming today is August 24, 2012):
December 1, 2012
November 1, 2012
June 1, 2012
June 30, 2012
In the following way:
November 1, 2012
December 1, 2012
June 30, 2012
June 1, 2012
This is such a way that it shows the events that have NOT yet happened first, and from soonest to furthest away, then show past events, from closest to farthest.
You can assume the table structure is:
ID name event_date
1 Test 1351742400 # All dates are Unix Time
2 Test2 1354338000
SELECT ID, name, event_date
FROM yourtable
ORDER BY event_date < UNIX_TIMESTAMP(), ABS(UNIX_TIMESTAMP() - event_date)
See it working online: sqlfiddle