View the step-by-step solution to:

Question

Premise:

You have a table with one column, `original_date`, of datatype string

src="/qa/attachment/11037846/" alt="Pic1.PNG" />

Question:


Write a SQL query to calculate two more columns -

  1. `end_of_week ` - the date of the next Sunday from `original_date`. If `original_date` is already a Sunday, this field should be the same value
  2. `end_of_month ` - the value of the end of month date

An acceptable solution is one which works for any valid date in the string format of `original_date`.

With end_of_month and end_of_week computed 

pic2.PNG


Additional Info:

20190825 is a Sunday, so the `end_of_week` for that value is still that same date.

20190827 is a Tuesday, and the next Sunday is on 20190901

 

 Expected Output

20190825 2019-08-25 2019-08-31

20190826 2019-09-01 2019-08-31

20190827 2019-09-01 2019-08-31

20190828 2019-09-01 2019-08-31

20190829 2019-09-01 2019-08-31

20190830 2019-09-01 2019-08-31

20190831 2019-09-01 2019-08-31

20190901 2019-09-01 2019-09-30


Use MYSQL

Pic1.PNG

pic2.PNG

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 MYSQL tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors