使用 SQL (MySQL) 从日期列中获取所有唯一年份 [英] Get all unique years from a date column using SQL (MySQL)

查看:35
本文介绍了使用 SQL (MySQL) 从日期列中获取所有唯一年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MySQL 表,其中包含一个名为created"的日期时间列,其中包含插入记录的日期和时间.这个表现在有大约 30 条记录.我想从这个表中获取所有发生的年份(唯一的,不是每条记录).有没有办法使用 MySQL 查询来做到这一点?

I have a MySQL table with a datetime column named 'created' which contains the date and time the record was inserted. This table has about 30 records right now. I want to get all occuring years (unique, not per record) from this table. Is there a way to do this using a MySQL query?

推荐答案

SELECT DISTINCT YEAR(created) FROM table

这篇关于使用 SQL (MySQL) 从日期列中获取所有唯一年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆