//获取当前时间; 2020-05 var d_n = DateTime.Now; StringBuilder sb = new StringBuilder(); sb.AppendFormat(" select '{0}' AS M ", d_n.ToString("yyy-MM")); for (int i = 1; i < 12; i++) { sb.AppendFormat(" UNION ALL select '{0}' ", d_n.AddMonths(-i).ToString("yyy-MM")); } var sql = sb.ToString();