简体   繁体   English

从SQL日期解析年份

[英]Parse year from SQL Date

I'm currently writing a Java app that interfaces with a MySQL database. 我目前正在编写与MySQL数据库连接的Java应用程序。
My problem is that I'm trying to write a function that fills a JComboBox with the unique year-values registered in the database. 我的问题是我正在尝试编写一个函数,该函数用数据库中注册的唯一年份值填充JComboBox。
I could use UNIQE on the date-field in the SQL query, but that would only exclude some of the dates, not all-but-one-date-per-year. 我可以在SQL查询的日期字段上使用UNIQE,但是那只会排除某些日期,而不是每年的所有日期。
Any help would be greatly appreciated. 任何帮助将不胜感激。

SELECT DISTINCT YEAR(yourDateColumn) FROM yourTable;

使用年份功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM