当前位置:   article > 正文

mysql统计最近12月数据--查询倒推12月份_sql查询按当前日期倒退十二个月有数据的月份个数

sql查询按当前日期倒退十二个月有数据的月份个数

mysql统计最近12月数据–查询倒推12月份

select date_format(curdate(),'%Y-%m') AS `mon` union

select date_format((curdate() - interval 1 month),'%Y-%m') AS `mon` union

select date_format((curdate() - interval 2 month),'%Y-%m') AS `mon` union

select date_format((curdate() - interval 3 month),'%Y-%m') AS `mon` union

select date_format((curdate() - interval 4 month),'%Y-%m') AS `mon` union

select date_format((curdate() - interval 5 month),'%Y-%m') AS `mon` union

select date_format((curdate() - interval 6 month),'%Y-%m') AS `mon` union

select date_format((curdate() - interval 7 month),'%Y-%m') AS `mon` union

select date_format((curdate() - interval 8 month),'%Y-%m') AS `mon` union

select date_format((curdate() - interval 9 month),'%Y-%m') AS `mon` union

select date_format((curdate() - interval 10 month),'%Y-%m') AS `mon` union

select date_format((curdate() - interval 11 month),'%Y-%m') AS `mon`
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

该语句可以用于条形图统计,横坐标最近12个月份节点展示;
可用于连接查询数据集合。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/313803
推荐阅读
相关标签
  

闽ICP备14008679号