编写SQL查询以查找从日期开始的年份

时间:2022-09-26 16:05:53

First of all I've try to do this query, in different format. but, I have not get any solution. so, i wants to solve this doubt in particular method and different method. And I want the exact solution this table.

首先,我尝试以不同的格式进行此查询。但是,我没有得到任何解决方案。所以,我想用特定的方法和不同的方法来解决这个疑问。我想要这个表的确切解决方案。

Write a SQL Query to find year from date.

编写SQL查询以查找从日期开始的年份。

SELECT YEAR(GETDATE()) as "Year";

   o_id         no.order          o_date         amount 
    --------------------------------------------------
    2             6                1-2-11         120
    3             7                2-2-11         130
    5             5                3-2-11         100
    6             1                4-2-11         50

note: the source getting from

注意:源来自

3 个解决方案

#1


3  

SELECT YEAR(GETDATE());

Source: Documentation

Or

SELECT DATE_FORMAT(GETDATE(), '%Y');

Source: Documentation

Example:

SELECT  o_id, amount, YEAR(o_date) as year
FROM your_table

#2


2  

select YEAR(STR_TO_DATE('1-2-11','%d-%m-%Y')) year;

#3


1  

Bart already pointed to the solution... manual has a line :

巴特已经指出了解决方案......手册有一条线:

mysql> SELECT YEAR('1987-01-01');
        -> 1987

#1


3  

SELECT YEAR(GETDATE());

Source: Documentation

Or

SELECT DATE_FORMAT(GETDATE(), '%Y');

Source: Documentation

Example:

SELECT  o_id, amount, YEAR(o_date) as year
FROM your_table

#2


2  

select YEAR(STR_TO_DATE('1-2-11','%d-%m-%Y')) year;

#3


1  

Bart already pointed to the solution... manual has a line :

巴特已经指出了解决方案......手册有一条线:

mysql> SELECT YEAR('1987-01-01');
        -> 1987