这个sql怎么写?
时间:2011-12-25
来源:互联网
表1:
id name adate
1 n1 2011.3.11
2 n2 2011.4.12
3 n3 2011.3.21
期望统计结果:
月份 数量
1 0
2 0
3 2
4 1
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
id name adate
1 n1 2011.3.11
2 n2 2011.4.12
3 n3 2011.3.21
期望统计结果:
月份 数量
1 0
2 0
3 2
4 1
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
作者: ashyrabbit 发布时间: 2011-12-25
with tempyeartable as
(
select '01' as month,'2011-01' as yymonth from dual
union
select '02' as month,'2011-02' as yymonth from dual
union
select '03' as month,'2011-03' as yymonth from dual
union
select '04' as month,'2011-04' as yymonth from dual
union
select '05' as month,'2011-05' as yymonth from dual
union
select '06' as month,'2011-06' as yymonth from dual
union
select '07' as month,'2011-07' as yymonth from dual
union
select '08' as month,'2011-08' as yymonth from dual
union
select '09' as month,'2011-09' as yymonth from dual
union
select '10' as month,'2011-10' as yymonth from dual
union
select '11' as month,'2011-11' as yymonth from dual
union
select '12' as month,'2011-12' as yymonth from dual
),
selecttable as
(
select to_char(adate,'yyyy-mm') t_mm,count(*) num
from 表1
group by to_char(adate,'yyyy-mm')
)
select b.month,nvl(a.num,0)
from selecttable a,tempyeartable b
where a.t_mm(+) = b.yymonth
order by month
(
select '01' as month,'2011-01' as yymonth from dual
union
select '02' as month,'2011-02' as yymonth from dual
union
select '03' as month,'2011-03' as yymonth from dual
union
select '04' as month,'2011-04' as yymonth from dual
union
select '05' as month,'2011-05' as yymonth from dual
union
select '06' as month,'2011-06' as yymonth from dual
union
select '07' as month,'2011-07' as yymonth from dual
union
select '08' as month,'2011-08' as yymonth from dual
union
select '09' as month,'2011-09' as yymonth from dual
union
select '10' as month,'2011-10' as yymonth from dual
union
select '11' as month,'2011-11' as yymonth from dual
union
select '12' as month,'2011-12' as yymonth from dual
),
selecttable as
(
select to_char(adate,'yyyy-mm') t_mm,count(*) num
from 表1
group by to_char(adate,'yyyy-mm')
)
select b.month,nvl(a.num,0)
from selecttable a,tempyeartable b
where a.t_mm(+) = b.yymonth
order by month
作者: zxf261 发布时间: 2011-12-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28