在mysql中显示月份名称而不是月份编号

编程入门 行业动态 更新时间:2024-10-08 06:24:41
本文介绍了在mysql中显示月份名称而不是月份编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

编写查询以显示月份名称和 2013 年每个月安排的事件数,按月份排序.为月份名称指定一个别名为 month_name,为计划的事件数指定一个别名为 number_of_events.月份名称必须显示为一月、二月...我尝试了以下查询,但没有执行:

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 ;

表名:

event

列:

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

推荐答案

你应该使用 MONTHNAME(date) - 像这样:

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

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

更多推荐

在mysql中显示月份名称而不是月份编号

本文发布于:2023-07-18 08:07:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142696.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不是   编号   名称   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!