SQL嵌套查询,下面的句子怎么连一起啊! 急救啊!

来源:百度知道 编辑:UC知道 时间:2024/09/20 07:41:08
select Count(id) as b from xy_customer_kee
where convert(varchar(7),data_time,126)='2009-01'
select Count(id) as b from xy_customer_kee
where convert(varchar(7),data_time,126)='2009-02'
select Count(id) as b from xy_customer_kee
where convert(varchar(7),data_time,126)='2009-03'
不好意思!没有分数了

查09年1、2、3月的

select Count(id) as b from xy_customer_kee
where convert(varchar(7),data_time,126) in ('2009-01','2009-02','2009-03')
group by convert(varchar(7),data_time,126)

查09年所有月份
select convert(varchar(7),data_time,126) a
,Count(id) as b from xy_customer_kee
where convert(varchar(4),data_time,126) ='2009'
group by convert(varchar(7),data_time,126)

连在一起
select Count(id) as b from xy_customer_kee
where convert(varchar(7),data_time,126)='2009-01'
union all
select Count(id) as b from xy_customer_kee
where convert(varchar(7),data_time,126)='2009-02'
union all
select Count(id) as b from xy_customer_kee
where convert(varchar(7),data_time,126)='2009-03'

每个月的都显示:

create table tb (
mon varchar(7)
)

insert into tb (mon) values('2009-01')
insert into tb (mon) values('20