SQL queris, | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

SQL queris,

I have a task I have been given to solve it, but I can't find my way through it, can anyone help me, please! "A query called Birth month events.sql which shows all the events which took place in your month of birth (ie whose date was on or after the first date of your birth month, and before or on the last day of your birth month)."

4th Nov 2018, 4:59 PM
Benjamin Martin Chavula
Benjamin Martin Chavula - avatar
3 Answers
+ 6
rudolph flash LOL... It's entirely possible I mixed something incompatible from T-SQL into this query. However, I'm pretty certain everything in the query works with MySQL. There's a lot of overlap between T-SQL and MySQL's implementation of SQL.
7th Nov 2018, 7:16 AM
David Carroll
David Carroll - avatar
+ 4
Assuming this is in MySQL, one approach is to declare a start and end date based on your birthdate: DECLARE @birth_date as DATE DECLARE @start_date as DATE DECLARE @end_date as DATE SET @birth_date = CONVERT(DATE, '1995-10-14') SET @start_date = DATEADD(m, DATEDIFF(m, 0, @birth_date), 0) SET @end_date = LAST_DAY(@birth_date) SELECT * FROM events WHERE event_date BETWEEN @start_date AND @end_date NOTE: I've not yet tested the syntax. It should be close though.
7th Nov 2018, 6:03 AM
David Carroll
David Carroll - avatar
+ 2
Can you describe your table structure (field definitions)? and what have you tried this far? have you tried to use MONTH function on the WHERE clause to filter out events on a particular month? that would be my idea though.
6th Nov 2018, 11:03 AM
Ipang