愿天天向上,愿学以致用,愿掌握生活

SQL把日期转换为季度来作查询

上一篇 / 下一篇  2007-10-03 15:36:38 / 天气: 晴朗 / 心情: 一般 / 个人分类:数据库

SQL 里面没有季度函数

Select Season = Case when month(日期) in (1,2,3) then '一季度'
                     when  month(日期) in (4,5,6) then '二季度'
                     when  month(日期) in (7,8,9) then '三季度'
                     when  month(日期) in (10,11,12) then '四季度' end ,
    count(*)
    from tablename
    group by    Case when month(日期) in (1,2,3) then '一季度'
                     when  month(日期) in (4,5,6) then '二季度'
                     when  month(日期) in (7,8,9) then '三季度'
                     when  month(日期) in (10,11,12) then '四季度' end

查询结果为 按季度分组后的各季度记录数量


TAG: 季度 数据库

 

评分:0

我来说两句

日历

« 2024-05-20  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 21607
  • 日志数: 30
  • 建立时间: 2007-10-02
  • 更新时间: 2007-11-14

RSS订阅

Open Toolbar