我需要以一种可读的方式总结这些年来每个月的面试次数。
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的形式返回月份,类似于‘一月’,而不是从‘月份’函数中返回默认的INT。
发布于 2019-04-28 20:58:07
对于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对于 Server
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发布于 2019-04-28 20:48:25
一个适用于大多数DBMS的解决方案是一个CASE表达式。
SELECT CASE month(i.date)
WHEN 1 THEN
'January'
...
WHEN 12 THEN
'December'
END month,
year(i.date) year,
count(i.id) number_of_interviews
FROM interviews i
GROUP BY month(i.date),
year(i.date)
ORDER BY year(i.date) DESC,
month(i.date) ASC;发布于 2019-04-30 00:13:21
SELECT count(1), format(dateColumn, 'yyyy-MM')
FROM tableName
GROUP BY format(dateColumn, 'yyyy-MM')
ORDER BY 2https://stackoverflow.com/questions/55894376
复制相似问题