表中两个字段 start_date 、end_date 均为日期型end_date - start_date = 天数差值现想对该差值进行分组统计,如:差值   总数
1       7
2       15
5       9
9       11该如何写 SQL ?  谢谢

解决方案 »

  1.   

    select (end_date - start_date) a, count(*) b from table group by (end_date - start_date)  
      

  2.   


    select (end_date - start_date) as "差值", count(*) as "总数" from test
     group by (end_date - start_date)
     order by "差值";
      

  3.   

    --oracle 日期直接相减,没有相减函数,粒度为天
    select ceil(end_date - start_date) a, count(*) b from table group by ceil(end_date - start_date)