MySQL组由同一列中的不同值组成

问题描述 投票:0回答:1

我想按年份对输出进行分组,以便有2行。在2019年排成一排,在2020年排成一排。甚至有可能吗?是否有类似的输出变体?

这是我的代码:

select count(*)
     , leirueck 
  from ausleihe 
 where leirueck between "2019-02-01" and "2019-02-10" 
    or leirueck between "2020-02-01" and "2020-02-10" 
 group  
    by leirueck 

And here the output

enter image description here

mysql
1个回答
0
投票

如果使用mysql year()函数在日期字段中按年份分组,则>

select count(*)
     , year(leirueck)
  from ausleihe 
 where leirueck between "2019-02-01" and "2019-02-10" 
    or leirueck between "2020-02-01" and "2020-02-10" 
 group  
    by year(leirueck) 
© www.soinside.com 2019 - 2024. All rights reserved.