sql - 按 MONTH 分组日期时如何将月份从 INT 转换为 VARCHAR
问题描述
我需要以一种可读的方式总结这些年来每个月的采访次数。
SELECT month(i.Date) AS Month, Year(i.Date) AS Year, Count(i.Id) AS' Number of Interviews'
FROM Interviews i
GROUP BY month(i.Date), year(i.Date)
ORDER BY year(i.Date) DESC, month(Date) ASC
我希望查询以 VARCHAR 形式返回 Month,例如 'January' 而不是来自 'month' 函数的默认 INT。
解决方案
对于MySql,它将是:
SELECT
monthname(i.Date) AS Month,
Year(i.Date) AS Year,
Count(i.Id) AS `Number of Interviews`
FROM Interviews i
GROUP BY month(i.Date), monthname(i.Date), year(i.Date)
ORDER BY year(i.Date) DESC, month(i.Date) ASC
对于SQL 服务器:
SELECT
datename(month, i.date) AS Month,
Year(i.Date) AS Year,
Count(i.Id) AS [Number of Interviews]
FROM Interviews i
GROUP BY month(i.Date), datename(month, i.date), year(i.Date)
ORDER BY year(i.Date) DESC, month(i.Date) ASC
推荐阅读
- json - 如何在 Json 的文件中包含其他文件?
- spring-boot - Spring Security OAuth2 - 资源服务器访问 HTTP 请求,客户端凭据授予类型
- flutter - 在颤动中按下时如何打印通话记录?
- java - Spring Framework Dao : type cannot be null error
- python - Python and Calabi Yau Data
- c++ - Ternar operator for 3 cases
- python - Getting 504 Gateway Time-out for Django on Ubuntu
- git - AEM 6.5 中的版本控制元数据更改
- python - AndroRAT Error while executing with python
- git - How to make the parent git folder always point to latest commit whenever there is a new commit in child module(submodule) - Any Alternative?