last day (16 days later) » 

3:40 PM
1
A: How to add month name with 0 total if data not exist in mysql?

Barbaros ÖzhanKeep using LEFT JOIN (but only once) with a integer generator upto 12 (instead of month names, also easy using within the ORDER BY clause ), since you are able to get the month names by monthname() function. From your second query, I considered the current year. So, use : SET @year=YEAR(NOW()); ...

 
Ok, I'll try in a while and let you know.
I have checked and this works fine for the current year. I just need one more level up. For example, I have a date 2018-10-10 Then I need data from that 2010's month to current month.
By the way, this query looks awesome. I have never imagined that I could run this type of query. Maybe it may take some time to understand how this works. :)
 
thank you, take it easy :) @SachinShah
 
This works me. And thanks for this awesome answer. :)
 
@SachinShah you're welcome friend.
 
This query is all most correct and also in same format which I want. After test your query I found that it sums correctly in the year of 2019 but not in 2018. Can you please tell me where I have to look. I didn't get much idea in this query.
 
3:40 PM
Hi @SachinShah. I was feeling tired last night. Let me check in the day again. Now it's about 4 AM here :) See you.
 
It's okay Take rest ... And check when you fell fresh ...
 
OK I fixed @SachinShah .
 
Thanks @Barbaros Özhan. I'll check and let you know.
 
@SachinShah did you look at the demo2 ..?
 
Let me try again.
Yes I looked into demo 2.
Hi
Sorry it was my typo. Now I'm getting 2018 data as well.
Can you please share any ref to understand your query?
 
3:42 PM
 
First of all, Thank you so so much for the support.
 
you're welcome :)
 
I didn't get that at which point you set the year 2018.
 
I'm looking for the minumum start_time and coming towards the current year
notice HAVING year >= ( SELECT MIN( YEAR(start_time) ) FROM table_u )
 
I want to make it dynamic so I'm gone a set the date in 2015 in db for test.
 
3:46 PM
yes, HAVING year >= ( SELECT MIN( YEAR(start_time) ) FROM table_u ) condition dynamically determines the least year
and year(now()) determines the current year
 
Ok just a min. I'm trying. :)
See I have set the date in 2015 but I got data till 2016 and also in 2016 I didn't get 12 month.
I changed one data with this date -> 2015-07-02 00:00:00
 
yes, I don't know the reason (very interesting :) ), it works only for year>= 2017
dynamically
the subquery returns 41 rows at most
the issue should be related to this
 
You mean limit issue ?
 
e.g. it's OK for last three year
perhaps
related to the limit clause
even in MySQL 8
 
4:01 PM
You mean mysql has limitation to fetch only last 3 years old data?
 
I mean subquery fetches only 41 rows
at least from the fiddle
you have mysql installed on your machine, don't you?
 
Yes, It's installed.
 
do you meet the same restriction(41 rows)
?
 
Yes I got same restriction.
 
perhaps it's a property set by DB parameter ...
 
4:04 PM
I got only 40 records.
 
Unfortunately I don't know
 
How could I address that property.
 

  last day (16 days later) »