Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 SQL Server 2008 的表中有行
请告诉我如何从表中选择唯一的年份?
PS:在这个表中唯一的年份是 2013
使用该YEAR函数,DISTINCT如下所示:
YEAR
DISTINCT
SELECT DISTINCT YEAR([date]) FROM Tablename;
SQL 小提琴演示
这会给你:
| YEAR | -------- | 2013 |
要使用 order by 子句,请给它一个别名并按此别名排序,而不是原始名称,如下所示:
SELECT DISTINCT YEAR([date]) AS Year FROM Tablename ORDER By Year;