发布网友 发布时间:2022-04-23 17:34
共3个回答
热心网友 时间:2022-04-08 12:58
sqlserver:
oracle:
select to_char(add_months(sysdate, -t.rn), 'yyyy-mm')热心网友 时间:2022-04-08 14:16
SQLServer版的写法:
SELECT left(convert(varchar(10),DATEADD(mm,DATEDIFF(mm,0,getdate()),0),120),7)YD into #YD
declare @Y int
set @Y=1
while @Y<DATEPART(month, GETDATE())
begin
insert #YD
select Left(convert(varchar(10),dateadd(month,-@Y,GETDATE()),120),7)
set @Y=@Y+1
end
select * from #YD order by YD
热心网友 时间:2022-04-08 15:50
mysql> select DATE_FORMAT('1997-10-04 22:23:00', '%Y/%m ');
+----------------------------------------------+
| DATE_FORMAT('1997-10-04 22:23:00', '%Y/%m ') |
+----------------------------------------------+
| 1997/10 |
+----------------------------------------------+