我有sql查询
select
DISTINCT {fn MONTHNAME(entrydate)} AS monthname,
emirate_name,
location,
price,
bedroom
from itf_property
where
emirate_name='Dubai'
and location='JBR'
and bedroom='2'
group by monthname
order by id
我想选择从 1 月到 12 月的空月份,就像如果 1 月没有值那么它将显示 0。
上述查询的输出附有图片
最佳答案
如果在mysql上使用
select
DISTINCT {fn MONTHNAME(entrydate)} AS monthname,
emirate_name,
if(month is null, '0', month) as month,
location,
price,
bedroom
from itf_property
where
emirate_name='Dubai'
and location='JBR'
and bedroom='2'
group by monthname
order by id
关于php - 当 mysql 数据库中某些月份有空数据时,如何在使用 MONTHNAME 时包含所有月份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34334778/