Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
119 views
in Technique[技术] by (71.8m points)

ansi sql - display month name instead of month number in mysql

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...