display month name instead of month number in mysql

末鹿安然 提交于 2021-02-05 12:24:07

问题


Write a query to display the name of the month and the number of events scheduled in each month in the year 2013, sorted by month. Give an alias to the month name as month_name and the to the number of events scheduled as number_of_events. Name of the month must be displayed as January, February ... I tried the following query but its not executing:

select convert(varchar(10),month,date) as month_name, count(*) as number_of_events
from event where year(date)=2013 group by date order by date ;

table name:

event

columns :

id           bigint(20)    primary key
date         datetime
description  varchar(255)
invitation   varchar(255)
name         varchar(255)
organiser_id bigint(20)

回答1:


You should use MONTHNAME(date) - something like this:

select MONTHNAME(date),COUNT(*) from event where year(date)=2013 group by MONTH(date)


来源:https://stackoverflow.com/questions/31403972/display-month-name-instead-of-month-number-in-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!